@getpara/core-sdk 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ParaCore.js +809 -2003
- package/dist/cjs/constants.js +4 -1
- package/dist/cjs/services/AuthService.js +787 -0
- package/dist/cjs/services/BaseAuthFlowService.js +78 -0
- package/dist/cjs/services/ExternalWalletService.js +386 -0
- package/dist/cjs/services/LoginFlowService.js +163 -0
- package/dist/cjs/services/PollingService.js +448 -0
- package/dist/cjs/services/PortalUrlService.js +379 -0
- package/dist/cjs/services/PregenWalletService.js +442 -0
- package/dist/cjs/services/SessionManagementService.js +280 -0
- package/dist/cjs/services/SignupFlowService.js +185 -0
- package/dist/cjs/services/VerificationFlowService.js +242 -0
- package/dist/cjs/services/WalletService.js +577 -0
- package/dist/cjs/services/types/AuthServiceTypes.js +15 -0
- package/dist/cjs/services/types/BaseAuthFlowServiceTypes.js +15 -0
- package/dist/cjs/services/types/ExternalWalletServiceTypes.js +15 -0
- package/dist/cjs/services/types/LoginFlowServiceTypes.js +15 -0
- package/dist/cjs/services/types/PollingServiceTypes.js +15 -0
- package/dist/cjs/services/types/PortalUrlServiceTypes.js +15 -0
- package/dist/cjs/services/types/PregenWalletServiceTypes.js +15 -0
- package/dist/cjs/services/types/SessionManagementServiceTypes.js +15 -0
- package/dist/cjs/services/types/SignupFlowServiceTypes.js +15 -0
- package/dist/cjs/services/types/VerificationFlowServiceTypes.js +15 -0
- package/dist/cjs/services/types/WalletServiceTypes.js +15 -0
- package/dist/cjs/services/types/index.js +15 -0
- package/dist/cjs/state/CoreStateManager.js +297 -0
- package/dist/cjs/state/actors/authenticateWithEmailOrPhone.js +50 -0
- package/dist/cjs/state/actors/authenticateWithExternalWallet.js +50 -0
- package/dist/cjs/state/actors/authenticateWithFarcaster.js +50 -0
- package/dist/cjs/state/actors/authenticateWithFarcasterLegacy.js +50 -0
- package/dist/cjs/state/actors/authenticateWithTelegram.js +50 -0
- package/dist/cjs/state/actors/authenticateWithTelegramLegacy.js +50 -0
- package/dist/cjs/state/actors/checkUserState.js +53 -0
- package/dist/cjs/state/actors/claimWallets.js +56 -0
- package/dist/cjs/state/actors/connectExternalConnectors.js +54 -0
- package/dist/cjs/state/actors/connectExternalWallet.js +50 -0
- package/dist/cjs/state/actors/createGuestWallets.js +50 -0
- package/dist/cjs/state/actors/createWallets.js +73 -0
- package/dist/cjs/state/actors/polling.js +91 -0
- package/dist/cjs/state/actors/processAuthentication.js +50 -0
- package/dist/cjs/state/actors/setupAfterLogin.js +52 -0
- package/dist/cjs/state/actors/setupPara.js +50 -0
- package/dist/cjs/state/actors/signExternalWalletVerification.js +79 -0
- package/dist/cjs/state/actors/switchExternalWallet.js +50 -0
- package/dist/cjs/state/actors/verifyExternalWallet.js +50 -0
- package/dist/cjs/state/actors/verifyNewAccount.js +50 -0
- package/dist/cjs/state/actors/waitForExternalWalletProviders.js +54 -0
- package/dist/cjs/state/machines/authStateMachine.helpers.js +137 -0
- package/dist/cjs/state/machines/authStateMachine.js +1084 -0
- package/dist/cjs/state/machines/coreStateMachine.js +383 -0
- package/dist/cjs/state/machines/walletStateMachine.js +437 -0
- package/dist/cjs/state/types/auth.js +15 -0
- package/dist/cjs/state/types/core.js +15 -0
- package/dist/cjs/state/types/wallet.js +15 -0
- package/dist/cjs/types/{auth.js → accountLinking.js} +3 -3
- package/dist/cjs/types/authState.js +15 -0
- package/dist/cjs/types/coreApi.js +3 -1
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/types/serviceInterfaces.js +15 -0
- package/dist/cjs/types/util.js +15 -0
- package/dist/cjs/utils/formatting.js +6 -0
- package/dist/cjs/utils/retryBackoff.js +30 -0
- package/dist/cjs/utils/stateErrorHelpers.js +60 -0
- package/dist/cjs/utils/stateListener.js +129 -0
- package/dist/esm/ParaCore.js +812 -2031
- package/dist/esm/constants.js +3 -1
- package/dist/esm/services/AuthService.js +717 -0
- package/dist/esm/services/BaseAuthFlowService.js +25 -0
- package/dist/esm/services/ExternalWalletService.js +327 -0
- package/dist/esm/services/LoginFlowService.js +97 -0
- package/dist/esm/services/PollingService.js +389 -0
- package/dist/esm/services/PortalUrlService.js +320 -0
- package/dist/esm/services/PregenWalletService.js +393 -0
- package/dist/esm/services/SessionManagementService.js +236 -0
- package/dist/esm/services/SignupFlowService.js +119 -0
- package/dist/esm/services/VerificationFlowService.js +178 -0
- package/dist/esm/services/WalletService.js +514 -0
- package/dist/esm/services/types/AuthServiceTypes.js +0 -0
- package/dist/esm/services/types/BaseAuthFlowServiceTypes.js +0 -0
- package/dist/esm/services/types/ExternalWalletServiceTypes.js +0 -0
- package/dist/esm/services/types/LoginFlowServiceTypes.js +0 -0
- package/dist/esm/services/types/PollingServiceTypes.js +0 -0
- package/dist/esm/services/types/PortalUrlServiceTypes.js +0 -0
- package/dist/esm/services/types/PregenWalletServiceTypes.js +0 -0
- package/dist/esm/services/types/SessionManagementServiceTypes.js +0 -0
- package/dist/esm/services/types/SignupFlowServiceTypes.js +0 -0
- package/dist/esm/services/types/VerificationFlowServiceTypes.js +0 -0
- package/dist/esm/services/types/WalletServiceTypes.js +0 -0
- package/dist/esm/services/types/index.js +0 -0
- package/dist/esm/state/CoreStateManager.js +261 -0
- package/dist/esm/state/actors/authenticateWithEmailOrPhone.js +10 -0
- package/dist/esm/state/actors/authenticateWithExternalWallet.js +10 -0
- package/dist/esm/state/actors/authenticateWithFarcaster.js +10 -0
- package/dist/esm/state/actors/authenticateWithFarcasterLegacy.js +10 -0
- package/dist/esm/state/actors/authenticateWithTelegram.js +10 -0
- package/dist/esm/state/actors/authenticateWithTelegramLegacy.js +10 -0
- package/dist/esm/state/actors/checkUserState.js +13 -0
- package/dist/esm/state/actors/claimWallets.js +16 -0
- package/dist/esm/state/actors/connectExternalConnectors.js +14 -0
- package/dist/esm/state/actors/connectExternalWallet.js +10 -0
- package/dist/esm/state/actors/createGuestWallets.js +10 -0
- package/dist/esm/state/actors/createWallets.js +20 -0
- package/dist/esm/state/actors/polling.js +55 -0
- package/dist/esm/state/actors/processAuthentication.js +10 -0
- package/dist/esm/state/actors/setupAfterLogin.js +12 -0
- package/dist/esm/state/actors/setupPara.js +10 -0
- package/dist/esm/state/actors/signExternalWalletVerification.js +15 -0
- package/dist/esm/state/actors/switchExternalWallet.js +10 -0
- package/dist/esm/state/actors/verifyExternalWallet.js +10 -0
- package/dist/esm/state/actors/verifyNewAccount.js +10 -0
- package/dist/esm/state/actors/waitForExternalWalletProviders.js +14 -0
- package/dist/esm/state/machines/authStateMachine.helpers.js +92 -0
- package/dist/esm/state/machines/authStateMachine.js +1039 -0
- package/dist/esm/state/machines/coreStateMachine.js +343 -0
- package/dist/esm/state/machines/walletStateMachine.js +382 -0
- package/dist/esm/state/types/auth.js +0 -0
- package/dist/esm/state/types/core.js +0 -0
- package/dist/esm/state/types/wallet.js +0 -0
- package/dist/esm/types/authState.js +0 -0
- package/dist/esm/types/coreApi.js +3 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/types/serviceInterfaces.js +0 -0
- package/dist/esm/types/util.js +0 -0
- package/dist/esm/utils/formatting.js +6 -0
- package/dist/esm/utils/retryBackoff.js +7 -0
- package/dist/esm/utils/stateErrorHelpers.js +37 -0
- package/dist/esm/utils/stateListener.js +106 -0
- package/dist/types/ParaCore.d.ts +190 -119
- package/dist/types/PlatformUtils.d.ts +23 -0
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/services/AuthService.d.ts +72 -0
- package/dist/types/services/BaseAuthFlowService.d.ts +28 -0
- package/dist/types/services/ExternalWalletService.d.ts +44 -0
- package/dist/types/services/LoginFlowService.d.ts +9 -0
- package/dist/types/services/PollingService.d.ts +35 -0
- package/dist/types/services/PortalUrlService.d.ts +26 -0
- package/dist/types/services/PregenWalletService.d.ts +38 -0
- package/dist/types/services/SessionManagementService.d.ts +28 -0
- package/dist/types/services/SignupFlowService.d.ts +10 -0
- package/dist/types/services/VerificationFlowService.d.ts +17 -0
- package/dist/types/services/WalletService.d.ts +54 -0
- package/dist/types/services/types/AuthServiceTypes.d.ts +147 -0
- package/dist/types/services/types/BaseAuthFlowServiceTypes.d.ts +4 -0
- package/dist/types/services/types/ExternalWalletServiceTypes.d.ts +67 -0
- package/dist/types/services/types/LoginFlowServiceTypes.d.ts +19 -0
- package/dist/types/services/types/PollingServiceTypes.d.ts +82 -0
- package/dist/types/services/types/PortalUrlServiceTypes.d.ts +46 -0
- package/dist/types/services/types/PregenWalletServiceTypes.d.ts +73 -0
- package/dist/types/services/types/SessionManagementServiceTypes.d.ts +27 -0
- package/dist/types/services/types/SignupFlowServiceTypes.d.ts +18 -0
- package/dist/types/services/types/VerificationFlowServiceTypes.d.ts +90 -0
- package/dist/types/services/types/WalletServiceTypes.d.ts +109 -0
- package/dist/types/services/types/index.d.ts +11 -0
- package/dist/types/state/CoreStateManager.d.ts +36 -0
- package/dist/types/state/actors/authenticateWithEmailOrPhone.d.ts +8 -0
- package/dist/types/state/actors/authenticateWithExternalWallet.d.ts +8 -0
- package/dist/types/state/actors/authenticateWithFarcaster.d.ts +3 -0
- package/dist/types/state/actors/authenticateWithFarcasterLegacy.d.ts +3 -0
- package/dist/types/state/actors/authenticateWithTelegram.d.ts +3 -0
- package/dist/types/state/actors/authenticateWithTelegramLegacy.d.ts +8 -0
- package/dist/types/state/actors/checkUserState.d.ts +6 -0
- package/dist/types/state/actors/claimWallets.d.ts +8 -0
- package/dist/types/state/actors/connectExternalConnectors.d.ts +4 -0
- package/dist/types/state/actors/connectExternalWallet.d.ts +3 -0
- package/dist/types/state/actors/createGuestWallets.d.ts +3 -0
- package/dist/types/state/actors/createWallets.d.ts +10 -0
- package/dist/types/state/actors/polling.d.ts +3 -0
- package/dist/types/state/actors/processAuthentication.d.ts +10 -0
- package/dist/types/state/actors/setupAfterLogin.d.ts +5 -0
- package/dist/types/state/actors/setupPara.d.ts +2 -0
- package/dist/types/state/actors/signExternalWalletVerification.d.ts +7 -0
- package/dist/types/state/actors/switchExternalWallet.d.ts +3 -0
- package/dist/types/state/actors/verifyExternalWallet.d.ts +8 -0
- package/dist/types/state/actors/verifyNewAccount.d.ts +8 -0
- package/dist/types/state/actors/waitForExternalWalletProviders.d.ts +2 -0
- package/dist/types/state/machines/authStateMachine.d.ts +2570 -0
- package/dist/types/state/machines/authStateMachine.helpers.d.ts +57 -0
- package/dist/types/state/machines/coreStateMachine.d.ts +22033 -0
- package/dist/types/state/machines/walletStateMachine.d.ts +1049 -0
- package/dist/types/state/types/auth.d.ts +113 -0
- package/dist/types/state/types/core.d.ts +114 -0
- package/dist/types/state/types/wallet.d.ts +76 -0
- package/dist/types/types/authState.d.ts +66 -0
- package/dist/types/types/config.d.ts +5 -0
- package/dist/types/types/coreApi.d.ts +148 -298
- package/dist/types/types/index.d.ts +3 -1
- package/dist/types/types/methods.d.ts +1 -191
- package/dist/types/types/serviceInterfaces.d.ts +125 -0
- package/dist/types/types/util.d.ts +43 -0
- package/dist/types/types/wallet.d.ts +3 -1
- package/dist/types/utils/retryBackoff.d.ts +2 -0
- package/dist/types/utils/stateErrorHelpers.d.ts +2 -0
- package/dist/types/utils/stateListener.d.ts +47 -0
- package/package.json +5 -4
- /package/dist/esm/types/{auth.js → accountLinking.js} +0 -0
- /package/dist/types/types/{auth.d.ts → accountLinking.d.ts} +0 -0
package/dist/cjs/ParaCore.js
CHANGED
|
@@ -93,14 +93,21 @@ var import_node_forge = __toESM(require("node-forge"));
|
|
|
93
93
|
var import_utils = require("./cryptography/utils.js");
|
|
94
94
|
var import_userManagementClient = require("./external/userManagementClient.js");
|
|
95
95
|
var mpcComputationClient = __toESM(require("./external/mpcComputationClient.js"));
|
|
96
|
-
var import_shareDistribution = require("./shares/shareDistribution.js");
|
|
97
96
|
var import_types = require("./types/index.js");
|
|
98
|
-
var import_recovery = require("./shares/recovery.js");
|
|
99
97
|
var import_utils2 = require("./utils/index.js");
|
|
98
|
+
var import_stateListener = require("./utils/stateListener.js");
|
|
100
99
|
var import_errors = require("./errors.js");
|
|
101
100
|
var constants = __toESM(require("./constants.js"));
|
|
102
101
|
var import_enclave = require("./shares/enclave.js");
|
|
103
|
-
var
|
|
102
|
+
var import_AuthService = require("./services/AuthService.js");
|
|
103
|
+
var import_PollingService = require("./services/PollingService.js");
|
|
104
|
+
var import_CoreStateManager = require("./state/CoreStateManager.js");
|
|
105
|
+
var import_WalletService = require("./services/WalletService.js");
|
|
106
|
+
var import_PregenWalletService = require("./services/PregenWalletService.js");
|
|
107
|
+
var import_PortalUrlService = require("./services/PortalUrlService.js");
|
|
108
|
+
var import_SessionManagementService = require("./services/SessionManagementService.js");
|
|
109
|
+
var import_ExternalWalletService = require("./services/ExternalWalletService.js");
|
|
110
|
+
var _stateManager, _authService, _walletService, _externalWalletService, _pregenWalletService, _pollingService, _portalUrlService, _sessionManagementService, _debugLogsEnabled, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, waitForLoginProcess_fn, logout_fn;
|
|
104
111
|
if (typeof global !== "undefined") {
|
|
105
112
|
global.Buffer = global.Buffer || import_buffer.Buffer;
|
|
106
113
|
} else if (typeof window !== "undefined") {
|
|
@@ -114,26 +121,21 @@ const { pki, jsbn } = import_node_forge.default;
|
|
|
114
121
|
const _ParaCore = class _ParaCore {
|
|
115
122
|
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
116
123
|
__privateAdd(this, _ParaCore_instances);
|
|
124
|
+
__privateAdd(this, _stateManager);
|
|
125
|
+
__privateAdd(this, _authService);
|
|
126
|
+
__privateAdd(this, _walletService);
|
|
127
|
+
__privateAdd(this, _externalWalletService);
|
|
128
|
+
__privateAdd(this, _pregenWalletService);
|
|
129
|
+
__privateAdd(this, _pollingService);
|
|
130
|
+
__privateAdd(this, _portalUrlService);
|
|
131
|
+
__privateAdd(this, _sessionManagementService);
|
|
132
|
+
__privateAdd(this, _debugLogsEnabled);
|
|
117
133
|
this.popupWindow = null;
|
|
118
|
-
__privateAdd(this, _authInfo);
|
|
119
134
|
this.isSwitchingWallets = false;
|
|
120
135
|
this.isNativePasskey = false;
|
|
121
|
-
this.
|
|
136
|
+
this.isSetup = false;
|
|
122
137
|
this.accountLinkInProgress = void 0;
|
|
123
|
-
this.isEnclaveUser = false;
|
|
124
|
-
this.isAwaitingAccountCreation = false;
|
|
125
|
-
this.isAwaitingLogin = false;
|
|
126
|
-
this.isAwaitingFarcaster = false;
|
|
127
|
-
this.isAwaitingOAuth = false;
|
|
128
138
|
this.isWorkerInitialized = false;
|
|
129
|
-
/**
|
|
130
|
-
* The IDs of the currently active wallets, for each supported wallet type. Any signer integrations will default to the first viable wallet ID in this dictionary.
|
|
131
|
-
*/
|
|
132
|
-
this.currentWalletIds = {};
|
|
133
|
-
/**
|
|
134
|
-
* Wallets associated with the `ParaCore` instance.
|
|
135
|
-
*/
|
|
136
|
-
this.externalWallets = {};
|
|
137
139
|
this.onRampPopup = void 0;
|
|
138
140
|
this.nonPersistedStorageKeys = [];
|
|
139
141
|
this.localStorageGetItem = (key) => {
|
|
@@ -167,7 +169,8 @@ const _ParaCore = class _ParaCore {
|
|
|
167
169
|
return this.platformUtils.sessionStorage.removeItem(key);
|
|
168
170
|
};
|
|
169
171
|
this.retrieveSessionCookie = () => {
|
|
170
|
-
|
|
172
|
+
var _a;
|
|
173
|
+
return (_a = __privateGet(this, _sessionManagementService)) == null ? void 0 : _a.sessionCookie;
|
|
171
174
|
};
|
|
172
175
|
this.retrieveEnclaveJwt = () => {
|
|
173
176
|
return this.enclaveJwt;
|
|
@@ -182,18 +185,21 @@ const _ParaCore = class _ParaCore {
|
|
|
182
185
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
183
186
|
const isAll = type === "all";
|
|
184
187
|
if (isAll || type === "local") {
|
|
185
|
-
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
186
|
-
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
188
|
+
yield this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
189
|
+
yield this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
187
190
|
}
|
|
188
191
|
if (isAll || type === "session") {
|
|
189
|
-
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
190
|
-
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
192
|
+
yield this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
193
|
+
yield this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
191
194
|
}
|
|
192
195
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
193
|
-
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
194
|
-
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
196
|
+
yield this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
197
|
+
yield this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
195
198
|
}
|
|
196
199
|
});
|
|
200
|
+
this.initExternalWalletProvider = (params) => __async(this, null, function* () {
|
|
201
|
+
yield __privateGet(this, _externalWalletService).initExternalWalletProvider(params);
|
|
202
|
+
});
|
|
197
203
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
198
204
|
try {
|
|
199
205
|
yield this.ctx.client.trackError({
|
|
@@ -252,7 +258,7 @@ const _ParaCore = class _ParaCore {
|
|
|
252
258
|
};
|
|
253
259
|
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
254
260
|
}
|
|
255
|
-
|
|
261
|
+
__privateGet(this, _authService).authInfo = authInfo;
|
|
256
262
|
};
|
|
257
263
|
this.updateEnclaveJwtFromStorage = () => {
|
|
258
264
|
this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
|
|
@@ -265,7 +271,7 @@ const _ParaCore = class _ParaCore {
|
|
|
265
271
|
}
|
|
266
272
|
};
|
|
267
273
|
this.updateUserIdFromStorage = () => {
|
|
268
|
-
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
274
|
+
__privateGet(this, _authService).userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
269
275
|
};
|
|
270
276
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
271
277
|
var _a;
|
|
@@ -306,12 +312,13 @@ const _ParaCore = class _ParaCore {
|
|
|
306
312
|
}, {}) : fromJson;
|
|
307
313
|
})();
|
|
308
314
|
this.setCurrentWalletIds(currentWalletIds);
|
|
309
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
315
|
+
if (Object.values(this.wallets).filter((w) => __privateGet(this, _walletService).isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
310
316
|
this.findWalletId(void 0, { forbidPregen: true });
|
|
311
317
|
}
|
|
312
318
|
};
|
|
313
319
|
this.updateSessionCookieFromStorage = () => {
|
|
314
|
-
this.sessionCookie = this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || void 0;
|
|
320
|
+
__privateGet(this, _sessionManagementService).sessionCookie = this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || void 0;
|
|
321
|
+
__privateGet(this, _sessionManagementService).isImportedSession = this.localStorageGetItem(constants.LOCAL_STORAGE_IS_IMPORTED_SESSION) === "true" || false;
|
|
315
322
|
};
|
|
316
323
|
this.updateLoginEncryptionKeyPairFromStorage = () => {
|
|
317
324
|
const loginEncryptionKey = this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
@@ -334,6 +341,25 @@ const _ParaCore = class _ParaCore {
|
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
343
|
});
|
|
344
|
+
this.setCurrentWalletIds = (...params) => __async(this, null, function* () {
|
|
345
|
+
const [currentWalletIds, { needsWallet = false, sessionLookupId, newDeviceSessionLookupId } = {}] = params;
|
|
346
|
+
return yield __privateGet(this, _walletService).setCurrentWalletIds(currentWalletIds, {
|
|
347
|
+
needsWallet,
|
|
348
|
+
sessionLookupId,
|
|
349
|
+
newDeviceSessionLookupId
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
/**
|
|
353
|
+
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
354
|
+
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
355
|
+
* @param {string} [walletId] the wallet ID to validate.
|
|
356
|
+
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
357
|
+
* @returns {string} the wallet ID originally passed, or the one found.
|
|
358
|
+
*/
|
|
359
|
+
this.findWalletId = (...params) => {
|
|
360
|
+
const [walletId, filters = {}] = params;
|
|
361
|
+
return __privateGet(this, _walletService).findWalletId(walletId, filters);
|
|
362
|
+
};
|
|
337
363
|
/**
|
|
338
364
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
339
365
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -343,12 +369,8 @@ const _ParaCore = class _ParaCore {
|
|
|
343
369
|
* @deprecated alias for `createWalletPerType`
|
|
344
370
|
**/
|
|
345
371
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
walletId,
|
|
349
|
-
rpcUrl
|
|
350
|
-
}) {
|
|
351
|
-
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
372
|
+
this.addCredential = (params) => __async(this, null, function* () {
|
|
373
|
+
return yield __privateGet(this, _authService).addCredential(params);
|
|
352
374
|
});
|
|
353
375
|
let env, apiKey;
|
|
354
376
|
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
@@ -379,6 +401,7 @@ const _ParaCore = class _ParaCore {
|
|
|
379
401
|
apiKey = apiKeyOrOpts;
|
|
380
402
|
}
|
|
381
403
|
if (!opts) opts = {};
|
|
404
|
+
__privateSet(this, _debugLogsEnabled, !!opts.enableDebugLogs);
|
|
382
405
|
let isE2E = false;
|
|
383
406
|
if (env === "E2E") {
|
|
384
407
|
isE2E = true;
|
|
@@ -413,7 +436,7 @@ const _ParaCore = class _ParaCore {
|
|
|
413
436
|
this.localStorageSetItem = this.sessionStorageSetItem;
|
|
414
437
|
}
|
|
415
438
|
this.persistSessionCookie = (cookie) => {
|
|
416
|
-
this.sessionCookie = cookie;
|
|
439
|
+
__privateGet(this, _sessionManagementService).sessionCookie = cookie;
|
|
417
440
|
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
418
441
|
constants.LOCAL_STORAGE_SESSION_COOKIE,
|
|
419
442
|
cookie
|
|
@@ -468,6 +491,59 @@ const _ParaCore = class _ParaCore {
|
|
|
468
491
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
469
492
|
return;
|
|
470
493
|
}
|
|
494
|
+
__privateSet(this, _authService, new import_AuthService.AuthService(this));
|
|
495
|
+
__privateSet(this, _walletService, new import_WalletService.WalletService(this));
|
|
496
|
+
__privateSet(this, _externalWalletService, new import_ExternalWalletService.ExternalWalletService(this));
|
|
497
|
+
__privateSet(this, _pregenWalletService, new import_PregenWalletService.PregenWalletService(this));
|
|
498
|
+
__privateSet(this, _pollingService, new import_PollingService.PollingService(this));
|
|
499
|
+
__privateSet(this, _portalUrlService, new import_PortalUrlService.PortalUrlService(this));
|
|
500
|
+
__privateSet(this, _sessionManagementService, new import_SessionManagementService.SessionManagementService(this));
|
|
501
|
+
__privateSet(this, _stateManager, new import_CoreStateManager.CoreStateManager(this));
|
|
502
|
+
__privateGet(this, _authService).init({
|
|
503
|
+
stateManager: __privateGet(this, _stateManager),
|
|
504
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
505
|
+
externalWalletService: __privateGet(this, _externalWalletService),
|
|
506
|
+
sessionManagementService: __privateGet(this, _sessionManagementService),
|
|
507
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
508
|
+
walletService: __privateGet(this, _walletService)
|
|
509
|
+
});
|
|
510
|
+
__privateGet(this, _walletService).init({
|
|
511
|
+
authService: __privateGet(this, _authService),
|
|
512
|
+
pollingService: __privateGet(this, _pollingService),
|
|
513
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
514
|
+
externalWalletService: __privateGet(this, _externalWalletService)
|
|
515
|
+
});
|
|
516
|
+
__privateGet(this, _externalWalletService).init({
|
|
517
|
+
stateManager: __privateGet(this, _stateManager),
|
|
518
|
+
authService: __privateGet(this, _authService),
|
|
519
|
+
walletService: __privateGet(this, _walletService)
|
|
520
|
+
});
|
|
521
|
+
__privateGet(this, _pollingService).init({
|
|
522
|
+
authService: __privateGet(this, _authService),
|
|
523
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
524
|
+
walletService: __privateGet(this, _walletService),
|
|
525
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
526
|
+
sessionManagementService: __privateGet(this, _sessionManagementService)
|
|
527
|
+
});
|
|
528
|
+
__privateGet(this, _pregenWalletService).init({
|
|
529
|
+
stateManager: __privateGet(this, _stateManager),
|
|
530
|
+
authService: __privateGet(this, _authService),
|
|
531
|
+
walletService: __privateGet(this, _walletService),
|
|
532
|
+
pollingService: __privateGet(this, _pollingService)
|
|
533
|
+
});
|
|
534
|
+
__privateGet(this, _portalUrlService).init({
|
|
535
|
+
authService: __privateGet(this, _authService),
|
|
536
|
+
walletService: __privateGet(this, _walletService),
|
|
537
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
538
|
+
sessionManagementService: __privateGet(this, _sessionManagementService)
|
|
539
|
+
});
|
|
540
|
+
__privateGet(this, _sessionManagementService).init({
|
|
541
|
+
authService: __privateGet(this, _authService),
|
|
542
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
543
|
+
walletService: __privateGet(this, _walletService),
|
|
544
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
545
|
+
externalWalletService: __privateGet(this, _externalWalletService)
|
|
546
|
+
});
|
|
471
547
|
this.initializeFromStorage();
|
|
472
548
|
import_utils2.setupListeners.bind(this)();
|
|
473
549
|
(0, import_utils2.autoBind)(this);
|
|
@@ -487,71 +563,183 @@ const _ParaCore = class _ParaCore {
|
|
|
487
563
|
"signTransaction"
|
|
488
564
|
]);
|
|
489
565
|
}
|
|
566
|
+
__privateGet(this, _stateManager).start();
|
|
490
567
|
}
|
|
491
568
|
setModalError(_error) {
|
|
492
569
|
return;
|
|
493
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* The current readiness state.
|
|
573
|
+
*/
|
|
574
|
+
get isReady() {
|
|
575
|
+
return __privateGet(this, _stateManager).getSnapshot().isReady;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* The current phase of the core flow.
|
|
579
|
+
*/
|
|
580
|
+
get corePhase() {
|
|
581
|
+
return __privateGet(this, _stateManager).getSnapshot().phase;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* The current phase of the authentication flow.
|
|
585
|
+
*/
|
|
586
|
+
get authPhase() {
|
|
587
|
+
return __privateGet(this, _stateManager).getSnapshot().authStatePhase;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* The current phase of the wallet flow.
|
|
591
|
+
*/
|
|
592
|
+
get walletPhase() {
|
|
593
|
+
return __privateGet(this, _stateManager).getSnapshot().walletStatePhase;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Any error that has occurred in the core flow.
|
|
597
|
+
*/
|
|
598
|
+
get error() {
|
|
599
|
+
return __privateGet(this, _stateManager).getSnapshot().error;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Get the current state of the core, auth, and wallet phases.
|
|
603
|
+
* @returns An object containing the current core, auth, and wallet state phases, along with any error.
|
|
604
|
+
*/
|
|
605
|
+
getCurrentState() {
|
|
606
|
+
const state = __privateGet(this, _stateManager).getSnapshot();
|
|
607
|
+
return {
|
|
608
|
+
corePhase: state.phase,
|
|
609
|
+
authPhase: state.authStatePhase,
|
|
610
|
+
walletPhase: state.walletStatePhase,
|
|
611
|
+
authStateInfo: state.authStateInfo,
|
|
612
|
+
error: state.error,
|
|
613
|
+
isReady: state.isReady
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Subscribe to changes in the core, auth, and wallet state phases.
|
|
618
|
+
*
|
|
619
|
+
* This method immediately calls the callback with the current state, then continues
|
|
620
|
+
* to call it whenever any phase changes. This ensures you never miss the initial state
|
|
621
|
+
* and can react to all subsequent changes.
|
|
622
|
+
*
|
|
623
|
+
* @param callback A function that will be called with the current state phases whenever they change.
|
|
624
|
+
* The callback receives an object containing `corePhase`, `authPhase`, `walletPhase`, and `error`.
|
|
625
|
+
*
|
|
626
|
+
* @returns A function that can be called to unsubscribe from the state changes.
|
|
627
|
+
* Always call this function when your component unmounts or when you no longer need updates
|
|
628
|
+
* to prevent memory leaks.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```typescript
|
|
632
|
+
* // React example
|
|
633
|
+
* useEffect(() => {
|
|
634
|
+
* const unsubscribe = paraClient.onStatePhaseChange((snapshot) => {
|
|
635
|
+
* console.log('Core phase:', snapshot.corePhase);
|
|
636
|
+
* console.log('Auth phase:', snapshot.authPhase);
|
|
637
|
+
* console.log('Wallet phase:', snapshot.walletPhase);
|
|
638
|
+
*
|
|
639
|
+
* if (snapshot.error) {
|
|
640
|
+
* console.error('Para error:', snapshot.error.message);
|
|
641
|
+
* }
|
|
642
|
+
* });
|
|
643
|
+
*
|
|
644
|
+
* return unsubscribe; // Cleanup on unmount
|
|
645
|
+
* }, [paraClient]);
|
|
646
|
+
*
|
|
647
|
+
* // Vue example
|
|
648
|
+
* onMounted(() => {
|
|
649
|
+
* const unsubscribe = paraClient.onStatePhaseChange((state) => {
|
|
650
|
+
* phases.value = state;
|
|
651
|
+
* });
|
|
652
|
+
*
|
|
653
|
+
* onUnmounted(unsubscribe);
|
|
654
|
+
* });
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
onStatePhaseChange(callback) {
|
|
658
|
+
let lastSnapshot = null;
|
|
659
|
+
const fullListener = (state) => {
|
|
660
|
+
const currentSnapshot = {
|
|
661
|
+
corePhase: state.phase,
|
|
662
|
+
authPhase: state.authStatePhase,
|
|
663
|
+
walletPhase: state.walletStatePhase,
|
|
664
|
+
authStateInfo: state.authStateInfo,
|
|
665
|
+
error: state.error,
|
|
666
|
+
isReady: state.isReady
|
|
667
|
+
};
|
|
668
|
+
if (!lastSnapshot || lastSnapshot.corePhase !== currentSnapshot.corePhase || lastSnapshot.authPhase !== currentSnapshot.authPhase || lastSnapshot.walletPhase !== currentSnapshot.walletPhase || lastSnapshot.error !== currentSnapshot.error || lastSnapshot.isReady !== currentSnapshot.isReady) {
|
|
669
|
+
lastSnapshot = currentSnapshot;
|
|
670
|
+
callback(currentSnapshot);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
return __privateGet(this, _stateManager).onStateChange(fullListener);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Subscribe to changes in the readiness state of the ParaCore instance.
|
|
677
|
+
* @param callback A function that will be called with the new readiness state.
|
|
678
|
+
* @returns A function that can be called to unsubscribe from the readiness state changes.
|
|
679
|
+
*/
|
|
680
|
+
onReadyStateChange(callback) {
|
|
681
|
+
let lastIsReady = null;
|
|
682
|
+
const unsubscribe = __privateGet(this, _stateManager).onStateChange((state) => {
|
|
683
|
+
if (lastIsReady !== state.isReady) {
|
|
684
|
+
lastIsReady = state.isReady;
|
|
685
|
+
callback(state.isReady);
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
return () => unsubscribe();
|
|
689
|
+
}
|
|
494
690
|
get authInfo() {
|
|
495
|
-
|
|
691
|
+
var _a;
|
|
692
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.authInfo;
|
|
496
693
|
}
|
|
497
694
|
get email() {
|
|
498
695
|
var _a;
|
|
499
|
-
return (
|
|
696
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.email;
|
|
500
697
|
}
|
|
501
698
|
get phone() {
|
|
502
699
|
var _a;
|
|
503
|
-
return (
|
|
700
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.phone;
|
|
504
701
|
}
|
|
505
702
|
get farcasterUsername() {
|
|
506
703
|
var _a;
|
|
507
|
-
return (
|
|
704
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.farcasterUsername;
|
|
508
705
|
}
|
|
509
706
|
get telegramUserId() {
|
|
510
707
|
var _a;
|
|
511
|
-
return (
|
|
708
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.telegramUserId;
|
|
512
709
|
}
|
|
513
710
|
get externalWalletWithParaAuth() {
|
|
514
|
-
|
|
515
|
-
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
711
|
+
return __privateGet(this, _externalWalletService).externalWalletWithParaAuth;
|
|
516
712
|
}
|
|
517
713
|
get externalWalletConnectionType() {
|
|
518
|
-
|
|
519
|
-
return "AUTHENTICATED";
|
|
520
|
-
} else if (this.isExternalWalletWithVerification) {
|
|
521
|
-
return "VERIFICATION";
|
|
522
|
-
} else if (!!Object.keys(this.externalWallets).length) {
|
|
523
|
-
const hasEmbeddedWallets = Object.keys(this.wallets).some((id) => !this.wallets[id].isExternal);
|
|
524
|
-
if (hasEmbeddedWallets) {
|
|
525
|
-
return "NONE";
|
|
526
|
-
} else {
|
|
527
|
-
return "CONNECTION_ONLY";
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return "NONE";
|
|
714
|
+
return __privateGet(this, _externalWalletService).externalWalletConnectionType;
|
|
531
715
|
}
|
|
532
|
-
get
|
|
716
|
+
get userId() {
|
|
533
717
|
var _a;
|
|
534
|
-
return (
|
|
718
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.userId;
|
|
719
|
+
}
|
|
720
|
+
get isEnclaveUser() {
|
|
721
|
+
return __privateGet(this, _authService).isEnclaveUser;
|
|
722
|
+
}
|
|
723
|
+
set isEnclaveUser(value) {
|
|
724
|
+
__privateGet(this, _authService).isEnclaveUser = value;
|
|
725
|
+
}
|
|
726
|
+
get isEmail() {
|
|
727
|
+
return __privateGet(this, _authService).isEmail;
|
|
535
728
|
}
|
|
536
729
|
get isPhone() {
|
|
537
|
-
|
|
538
|
-
return (0, import_user_management_client.isPhone)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
730
|
+
return __privateGet(this, _authService).isPhone;
|
|
539
731
|
}
|
|
540
732
|
get isFarcaster() {
|
|
541
|
-
|
|
542
|
-
return (0, import_user_management_client.isFarcaster)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
733
|
+
return __privateGet(this, _authService).isFarcaster;
|
|
543
734
|
}
|
|
544
735
|
get isTelegram() {
|
|
545
|
-
|
|
546
|
-
return (0, import_user_management_client.isTelegram)((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
736
|
+
return __privateGet(this, _authService).isTelegram;
|
|
547
737
|
}
|
|
548
738
|
get isExternalWalletAuth() {
|
|
549
|
-
|
|
550
|
-
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withFullParaAuth);
|
|
739
|
+
return __privateGet(this, _authService).isExternalWalletAuth;
|
|
551
740
|
}
|
|
552
741
|
get isExternalWalletWithVerification() {
|
|
553
|
-
|
|
554
|
-
return (0, import_user_management_client.isExternalWallet)((_a = __privateGet(this, _authInfo)) == null ? void 0 : _a.auth) && !!((_c = (_b = __privateGet(this, _authInfo)) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.withVerification);
|
|
742
|
+
return __privateGet(this, _authService).isExternalWalletWithVerification;
|
|
555
743
|
}
|
|
556
744
|
get partnerId() {
|
|
557
745
|
var _a;
|
|
@@ -565,45 +753,42 @@ const _ParaCore = class _ParaCore {
|
|
|
565
753
|
var _a;
|
|
566
754
|
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
567
755
|
}
|
|
756
|
+
get currentWalletIds() {
|
|
757
|
+
return __privateGet(this, _walletService).currentWalletIds;
|
|
758
|
+
}
|
|
568
759
|
get currentWalletIdsArray() {
|
|
569
|
-
|
|
570
|
-
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
571
|
-
(acc, { type }) => {
|
|
572
|
-
var _a2;
|
|
573
|
-
return [
|
|
574
|
-
...acc,
|
|
575
|
-
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
576
|
-
return [id, type];
|
|
577
|
-
})
|
|
578
|
-
];
|
|
579
|
-
},
|
|
580
|
-
[]
|
|
581
|
-
);
|
|
760
|
+
return __privateGet(this, _walletService).currentWalletIdsArray;
|
|
582
761
|
}
|
|
583
762
|
get currentWalletIdsUnique() {
|
|
584
|
-
return
|
|
763
|
+
return __privateGet(this, _walletService).currentWalletIdsUnique;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Wallets associated with the `ParaCore` instance. Retrieve a particular wallet using `para.wallets[walletId]`.
|
|
767
|
+
*/
|
|
768
|
+
get wallets() {
|
|
769
|
+
var _a;
|
|
770
|
+
return (_a = __privateGet(this, _walletService)) == null ? void 0 : _a.wallets;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Wallets associated with the `ParaCore` instance.
|
|
774
|
+
*/
|
|
775
|
+
get externalWallets() {
|
|
776
|
+
var _a;
|
|
777
|
+
return (_a = __privateGet(this, _externalWalletService)) == null ? void 0 : _a.externalWallets;
|
|
585
778
|
}
|
|
586
779
|
/**
|
|
587
780
|
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
588
781
|
*/
|
|
589
782
|
get pregenIds() {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
593
|
-
return acc;
|
|
594
|
-
}
|
|
595
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
596
|
-
[wallet.pregenIdentifierType]: [
|
|
597
|
-
.../* @__PURE__ */ new Set([...(_b = acc[wallet.pregenIdentifierType]) != null ? _b : [], wallet.pregenIdentifier])
|
|
598
|
-
]
|
|
599
|
-
});
|
|
600
|
-
}, {}));
|
|
783
|
+
var _a;
|
|
784
|
+
return (_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.pregenIds;
|
|
601
785
|
}
|
|
602
786
|
/**
|
|
603
787
|
* Whether the instance has multiple wallets connected.
|
|
604
788
|
*/
|
|
605
789
|
get isMultiWallet() {
|
|
606
|
-
|
|
790
|
+
var _a;
|
|
791
|
+
return this.currentWalletIdsArray.length > 1 || ((_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.guestWalletIdsArray.length) > 1;
|
|
607
792
|
}
|
|
608
793
|
get isNoWalletConfig() {
|
|
609
794
|
var _a;
|
|
@@ -668,60 +853,6 @@ const _ParaCore = class _ParaCore {
|
|
|
668
853
|
);
|
|
669
854
|
}
|
|
670
855
|
}
|
|
671
|
-
isWalletSupported(wallet) {
|
|
672
|
-
var _a, _b;
|
|
673
|
-
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || (0, import_utils2.isWalletSupported)((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
674
|
-
}
|
|
675
|
-
isWalletOwned(wallet) {
|
|
676
|
-
return this.isWalletSupported(wallet) && !(wallet == null ? void 0 : wallet.pregenIdentifier) && !(wallet == null ? void 0 : wallet.pregenIdentifierType) && !!this.userId && (wallet == null ? void 0 : wallet.userId) === this.userId;
|
|
677
|
-
}
|
|
678
|
-
isPregenWalletUnclaimed(wallet) {
|
|
679
|
-
return this.isWalletSupported(wallet) && (!(wallet == null ? void 0 : wallet.userId) || (wallet == null ? void 0 : wallet.isPregen) && !!(wallet == null ? void 0 : wallet.pregenIdentifier) && !!(wallet == null ? void 0 : wallet.pregenIdentifierType));
|
|
680
|
-
}
|
|
681
|
-
isPregenWalletClaimable(wallet) {
|
|
682
|
-
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet == null ? void 0 : wallet.pregenIdentifierType) || (0, import_utils2.isPregenIdentifierMatch)(
|
|
683
|
-
(wallet == null ? void 0 : wallet.pregenIdentifierType) === "EMAIL" ? this.email : (wallet == null ? void 0 : wallet.pregenIdentifierType) === "TELEGRAM" ? this.telegramUserId : this.getPhoneNumber(),
|
|
684
|
-
wallet == null ? void 0 : wallet.pregenIdentifier,
|
|
685
|
-
wallet == null ? void 0 : wallet.pregenIdentifierType
|
|
686
|
-
));
|
|
687
|
-
}
|
|
688
|
-
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
689
|
-
var _a, _b;
|
|
690
|
-
let error;
|
|
691
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
692
|
-
return true;
|
|
693
|
-
}
|
|
694
|
-
if (!this.wallets[walletId]) {
|
|
695
|
-
error = `wallet with id ${walletId} does not exist`;
|
|
696
|
-
} else {
|
|
697
|
-
const wallet = this.wallets[walletId];
|
|
698
|
-
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
699
|
-
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
700
|
-
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
701
|
-
} else if (!isOwned && !isUnclaimed) {
|
|
702
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
703
|
-
} else if (!this.isWalletSupported(wallet)) {
|
|
704
|
-
error = `wallet with id ${wallet.id} and type ${wallet.type} is not supported, supported types are: ${(((_b = this.partner) == null ? void 0 : _b.supportedWalletTypes) || []).map(({ type }) => type).join(", ")}`;
|
|
705
|
-
} else if (types && (!(0, import_utils2.getEquivalentTypes)(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
706
|
-
var _a2, _b2;
|
|
707
|
-
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
708
|
-
}))) {
|
|
709
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
710
|
-
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
711
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and scheme ${wallet == null ? void 0 : wallet.scheme} cannot be selected`;
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
if (error) {
|
|
715
|
-
if (throwError) {
|
|
716
|
-
throw new Error(error);
|
|
717
|
-
}
|
|
718
|
-
return false;
|
|
719
|
-
}
|
|
720
|
-
return true;
|
|
721
|
-
}
|
|
722
|
-
truncateAddress(...args) {
|
|
723
|
-
return (0, import_utils2.truncateAddress)(args[0], args[1], __spreadValues({ prefix: this.cosmosPrefix }, args[2] || {}));
|
|
724
|
-
}
|
|
725
856
|
/**
|
|
726
857
|
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
727
858
|
* @param {string} walletId the ID of the wallet address to display.
|
|
@@ -730,32 +861,9 @@ const _ParaCore = class _ParaCore {
|
|
|
730
861
|
* @param {TWalletType} options.addressType the type of address to display.
|
|
731
862
|
* @returns the formatted address
|
|
732
863
|
*/
|
|
733
|
-
getDisplayAddress(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const wallet2 = this.externalWallets[walletId];
|
|
737
|
-
return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, {
|
|
738
|
-
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
739
|
-
targetLength: options.targetLength
|
|
740
|
-
}) : wallet2.address;
|
|
741
|
-
}
|
|
742
|
-
const wallet = this.findWallet(walletId, options.addressType);
|
|
743
|
-
if (!wallet) {
|
|
744
|
-
return void 0;
|
|
745
|
-
}
|
|
746
|
-
let str;
|
|
747
|
-
let prefix;
|
|
748
|
-
switch (wallet.type) {
|
|
749
|
-
case "COSMOS":
|
|
750
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
751
|
-
str = (0, import_utils2.getCosmosAddress)(wallet.publicKey, prefix);
|
|
752
|
-
break;
|
|
753
|
-
default:
|
|
754
|
-
prefix = this.cosmosPrefix;
|
|
755
|
-
str = wallet.address;
|
|
756
|
-
break;
|
|
757
|
-
}
|
|
758
|
-
return options.truncate ? (0, import_utils2.truncateAddress)(str, wallet.type, { prefix, targetLength: options.targetLength }) : str;
|
|
864
|
+
getDisplayAddress(...params) {
|
|
865
|
+
const [walletId, options = {}] = params;
|
|
866
|
+
return __privateGet(this, _walletService).getDisplayAddress(walletId, options);
|
|
759
867
|
}
|
|
760
868
|
/**
|
|
761
869
|
* Returns a unique hash for a wallet suitable for use as an identicon seed.
|
|
@@ -763,13 +871,8 @@ const _ParaCore = class _ParaCore {
|
|
|
763
871
|
* @param {boolean} options.addressType used to format the hash for another wallet type.
|
|
764
872
|
* @returns the identicon hash string
|
|
765
873
|
*/
|
|
766
|
-
getIdenticonHash(
|
|
767
|
-
|
|
768
|
-
const wallet2 = this.externalWallets[walletId];
|
|
769
|
-
return `${wallet2.id}-${wallet2.address}-${wallet2.type}`;
|
|
770
|
-
}
|
|
771
|
-
const wallet = this.findWallet(walletId, overrideType);
|
|
772
|
-
return wallet ? `${wallet.id}-${wallet.address}-${wallet.type}` : void 0;
|
|
874
|
+
getIdenticonHash(...params) {
|
|
875
|
+
return __privateGet(this, _walletService).getIdenticonHash(...params);
|
|
773
876
|
}
|
|
774
877
|
getWallets() {
|
|
775
878
|
return this.wallets;
|
|
@@ -780,189 +883,7 @@ const _ParaCore = class _ParaCore {
|
|
|
780
883
|
}
|
|
781
884
|
constructPortalUrl(_0) {
|
|
782
885
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
783
|
-
|
|
784
|
-
const [
|
|
785
|
-
isCreate,
|
|
786
|
-
isLogin,
|
|
787
|
-
isOnRamp,
|
|
788
|
-
isOAuth,
|
|
789
|
-
isOAuthCallback,
|
|
790
|
-
isTelegramLogin,
|
|
791
|
-
isFarcasterLogin,
|
|
792
|
-
isAddNewCredential,
|
|
793
|
-
isSwitchWallets,
|
|
794
|
-
isExportPrivateKey,
|
|
795
|
-
isTxReview
|
|
796
|
-
] = [
|
|
797
|
-
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
798
|
-
["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets", "loginExternalWallet"].includes(type),
|
|
799
|
-
type === "onRamp",
|
|
800
|
-
type === "oAuth",
|
|
801
|
-
type === "oAuthCallback",
|
|
802
|
-
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
803
|
-
type === "loginFarcaster",
|
|
804
|
-
type === "addNewCredential",
|
|
805
|
-
type === "switchWallets",
|
|
806
|
-
type === "exportPrivateKey",
|
|
807
|
-
type === "txReview"
|
|
808
|
-
];
|
|
809
|
-
if (isOAuth && !opts.oAuthMethod) {
|
|
810
|
-
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
811
|
-
}
|
|
812
|
-
if (isCreate || isLogin) {
|
|
813
|
-
this.assertIsAuthSet();
|
|
814
|
-
}
|
|
815
|
-
let sessionId = opts.sessionId;
|
|
816
|
-
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin || isExportPrivateKey || isTxReview) && !sessionId) {
|
|
817
|
-
const session = yield this.touchSession(true);
|
|
818
|
-
sessionId = session.sessionId;
|
|
819
|
-
}
|
|
820
|
-
if (!this.loginEncryptionKeyPair) {
|
|
821
|
-
yield this.setLoginEncryptionKeyPair();
|
|
822
|
-
}
|
|
823
|
-
const shouldUseLegacyPortalUrl = opts.useLegacyUrl || !!opts.addNewCredentialPasskeyId || type === "loginAuth";
|
|
824
|
-
const base = type === "onRamp" || isTelegramLogin ? this.ctx.portalUrlOverride || (0, import_utils2.getPortalBaseURL)(this.ctx, isTelegramLogin, false, shouldUseLegacyPortalUrl) : yield this.getPortalURL(shouldUseLegacyPortalUrl);
|
|
825
|
-
let path;
|
|
826
|
-
switch (type) {
|
|
827
|
-
case "createPassword": {
|
|
828
|
-
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
829
|
-
break;
|
|
830
|
-
}
|
|
831
|
-
case "createPIN": {
|
|
832
|
-
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
833
|
-
break;
|
|
834
|
-
}
|
|
835
|
-
case "createAuth": {
|
|
836
|
-
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
case "loginPassword": {
|
|
840
|
-
path = "/web/passwords/login";
|
|
841
|
-
break;
|
|
842
|
-
}
|
|
843
|
-
case "loginAuth": {
|
|
844
|
-
path = "/web/biometrics/login";
|
|
845
|
-
break;
|
|
846
|
-
}
|
|
847
|
-
case "loginPIN": {
|
|
848
|
-
path = "/web/pin/login";
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
case "txReview": {
|
|
852
|
-
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
case "onRamp": {
|
|
856
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
case "telegramLoginVerify": {
|
|
860
|
-
path = `/auth/telegram/verify`;
|
|
861
|
-
break;
|
|
862
|
-
}
|
|
863
|
-
case "telegramLogin": {
|
|
864
|
-
path = `/auth/telegram`;
|
|
865
|
-
break;
|
|
866
|
-
}
|
|
867
|
-
case "oAuth": {
|
|
868
|
-
path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
|
|
869
|
-
break;
|
|
870
|
-
}
|
|
871
|
-
case "oAuthCallback": {
|
|
872
|
-
path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
|
|
873
|
-
break;
|
|
874
|
-
}
|
|
875
|
-
case "loginOTP": {
|
|
876
|
-
path = "/auth/otp";
|
|
877
|
-
break;
|
|
878
|
-
}
|
|
879
|
-
case "loginFarcaster": {
|
|
880
|
-
path = "/auth/farcaster";
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
case "switchWallets": {
|
|
884
|
-
path = `/auth/wallets`;
|
|
885
|
-
break;
|
|
886
|
-
}
|
|
887
|
-
case "addNewCredential": {
|
|
888
|
-
path = "/auth/add-new-credential";
|
|
889
|
-
break;
|
|
890
|
-
}
|
|
891
|
-
case "exportPrivateKey": {
|
|
892
|
-
path = `/web/users/${this.userId}/private-key/${opts.pathId}`;
|
|
893
|
-
break;
|
|
894
|
-
}
|
|
895
|
-
case "loginExternalWallet": {
|
|
896
|
-
path = "/auth/external-wallet";
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
case "connectExternalWallet": {
|
|
900
|
-
path = "/auth/connect-external-wallet";
|
|
901
|
-
break;
|
|
902
|
-
}
|
|
903
|
-
default: {
|
|
904
|
-
throw new Error(`invalid URL type ${type}`);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
let partner = void 0;
|
|
908
|
-
try {
|
|
909
|
-
partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
910
|
-
} catch (e) {
|
|
911
|
-
if (this.isPartnerOptional) {
|
|
912
|
-
partner = void 0;
|
|
913
|
-
} else {
|
|
914
|
-
throw e;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
918
|
-
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair),
|
|
919
|
-
sessionId
|
|
920
|
-
};
|
|
921
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
922
|
-
apiKey: this.ctx.apiKey,
|
|
923
|
-
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
924
|
-
partnerId: partner == null ? void 0 : partner.id
|
|
925
|
-
}, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
|
|
926
|
-
portalFont: ((_c = opts.portalTheme) == null ? void 0 : _c.font) || ((_d = this.portalTheme) == null ? void 0 : _d.font) || (partner == null ? void 0 : partner.font),
|
|
927
|
-
portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = this.portalTheme) == null ? void 0 : _f.borderRadius),
|
|
928
|
-
portalThemeMode: ((_g = opts.portalTheme) == null ? void 0 : _g.mode) || ((_h = this.portalTheme) == null ? void 0 : _h.mode) || (partner == null ? void 0 : partner.themeMode),
|
|
929
|
-
portalAccentColor: ((_i = opts.portalTheme) == null ? void 0 : _i.accentColor) || ((_j = this.portalTheme) == null ? void 0 : _j.accentColor) || (partner == null ? void 0 : partner.accentColor),
|
|
930
|
-
portalForegroundColor: ((_k = opts.portalTheme) == null ? void 0 : _k.foregroundColor) || ((_l = this.portalTheme) == null ? void 0 : _l.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor),
|
|
931
|
-
portalBackgroundColor: ((_m = opts.portalTheme) == null ? void 0 : _m.backgroundColor) || ((_n = this.portalTheme) == null ? void 0 : _n.backgroundColor) || (partner == null ? void 0 : partner.backgroundColor) || this.portalBackgroundColor,
|
|
932
|
-
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
933
|
-
portalTextColor: this.portalTextColor,
|
|
934
|
-
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
935
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
936
|
-
}), this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey) ? __spreadProps(__spreadValues({
|
|
937
|
-
authInfo: JSON.stringify(this.authInfo)
|
|
938
|
-
}, (0, import_user_management_client.isPhone)(this.authInfo.auth) ? (0, import_utils2.splitPhoneNumber)(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
939
|
-
pfpUrl: this.authInfo.pfpUrl,
|
|
940
|
-
displayName: this.authInfo.displayName,
|
|
941
|
-
userId: this.userId
|
|
942
|
-
}) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential ? __spreadProps(__spreadValues({
|
|
943
|
-
sessionId: thisDevice.sessionId,
|
|
944
|
-
encryptionKey: thisDevice.encryptionKey
|
|
945
|
-
}, opts.newDevice ? {
|
|
946
|
-
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
947
|
-
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
948
|
-
} : {}), {
|
|
949
|
-
pregenIds: JSON.stringify(this.pregenIds)
|
|
950
|
-
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
951
|
-
appScheme: opts.appScheme
|
|
952
|
-
} : {}), 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() }), {
|
|
953
|
-
addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
|
|
954
|
-
addNewCredentialPasswordId: opts.addNewCredentialPasswordId
|
|
955
|
-
}) : {}), isLogin && {
|
|
956
|
-
// Prior versions won't have this param which will skip the upgrade prompt
|
|
957
|
-
isBasicLoginUpgradeVersion: "true"
|
|
958
|
-
}), isExportPrivateKey || isTxReview ? {
|
|
959
|
-
sessionId: thisDevice.sessionId
|
|
960
|
-
} : {});
|
|
961
|
-
const url = (0, import_utils2.constructUrl)({ base, path, params });
|
|
962
|
-
if (opts.shorten) {
|
|
963
|
-
return yield (0, import_utils2.shortenUrl)(this.ctx, url, shouldUseLegacyPortalUrl);
|
|
964
|
-
}
|
|
965
|
-
return url;
|
|
886
|
+
return yield __privateGet(this, _portalUrlService).constructPortalUrl(type, opts);
|
|
966
887
|
});
|
|
967
888
|
}
|
|
968
889
|
static resolveEnvironment(env, apiKey) {
|
|
@@ -984,58 +905,182 @@ const _ParaCore = class _ParaCore {
|
|
|
984
905
|
}
|
|
985
906
|
return env;
|
|
986
907
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
908
|
+
// Create a dedicated interface for #authService
|
|
909
|
+
getAuthServiceInterface() {
|
|
910
|
+
const self2 = this;
|
|
911
|
+
return {
|
|
912
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this),
|
|
913
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
914
|
+
localStorageGetItem: this.localStorageGetItem.bind(this),
|
|
915
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
916
|
+
localStorageRemoveItem: this.localStorageRemoveItem.bind(this),
|
|
917
|
+
isPasskeySupported: this.isPasskeySupported.bind(this),
|
|
918
|
+
getVerificationEmailProps: this.getVerificationEmailProps.bind(this),
|
|
919
|
+
displayModalError: this.displayModalError.bind(this),
|
|
920
|
+
isPortal: this.isPortal.bind(this),
|
|
921
|
+
assertIsLinkingAccount: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).bind(this),
|
|
922
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
923
|
+
get loginEncryptionKeyPair() {
|
|
924
|
+
return self2.loginEncryptionKeyPair;
|
|
925
|
+
},
|
|
926
|
+
get isNativePasskey() {
|
|
927
|
+
return self2.isNativePasskey;
|
|
928
|
+
},
|
|
929
|
+
ctx: this.ctx,
|
|
930
|
+
get accountLinkInProgress() {
|
|
931
|
+
return self2.accountLinkInProgress;
|
|
932
|
+
},
|
|
933
|
+
partnerId: this.partnerId,
|
|
934
|
+
platformUtils: this.platformUtils,
|
|
935
|
+
externalWalletConnectionOnly: !!this.externalWalletConnectionOnly
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
// Create a dedicated interface for WalletService
|
|
939
|
+
getWalletServiceInterface() {
|
|
940
|
+
const self2 = this;
|
|
941
|
+
return {
|
|
942
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
943
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
944
|
+
isPortal: this.isPortal.bind(this),
|
|
945
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
946
|
+
getBackupKitEmailProps: this.getBackupKitEmailProps.bind(this),
|
|
947
|
+
retrieveSessionCookie: this.retrieveSessionCookie.bind(this),
|
|
948
|
+
isParaConnect: this.isParaConnect.bind(this),
|
|
949
|
+
ctx: this.ctx,
|
|
950
|
+
get partner() {
|
|
951
|
+
return self2.partner;
|
|
952
|
+
},
|
|
953
|
+
platformUtils: this.platformUtils,
|
|
954
|
+
cosmosPrefix: this.cosmosPrefix
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
// Create a dedicated interface for PregenWalletService
|
|
958
|
+
getPregenWalletServiceInterface() {
|
|
959
|
+
var _a;
|
|
960
|
+
const self2 = this;
|
|
961
|
+
return {
|
|
962
|
+
fetchPregenWalletsOverride: (_a = this.fetchPregenWalletsOverride) == null ? void 0 : _a.bind(this),
|
|
963
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
964
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
965
|
+
getBackupKitEmailProps: this.getBackupKitEmailProps.bind(this),
|
|
966
|
+
isPortal: this.isPortal.bind(this),
|
|
967
|
+
retrieveSessionCookie: this.retrieveSessionCookie.bind(this),
|
|
968
|
+
ctx: this.ctx,
|
|
969
|
+
platformUtils: this.platformUtils,
|
|
970
|
+
get partner() {
|
|
971
|
+
return self2.partner;
|
|
995
972
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
// Create a dedicated interface for PortalUrlService
|
|
976
|
+
getPortalUrlServiceInterface() {
|
|
977
|
+
const self2 = this;
|
|
978
|
+
return {
|
|
979
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
980
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
981
|
+
isPortal: this.isPortal.bind(this),
|
|
982
|
+
isPartnerOptional: this.isPartnerOptional,
|
|
983
|
+
ctx: this.ctx,
|
|
984
|
+
get loginEncryptionKeyPair() {
|
|
985
|
+
return self2.loginEncryptionKeyPair;
|
|
986
|
+
},
|
|
987
|
+
get portalTheme() {
|
|
988
|
+
return self2.portalTheme;
|
|
989
|
+
},
|
|
990
|
+
get portalPrimaryButtonColor() {
|
|
991
|
+
return self2.portalPrimaryButtonColor;
|
|
992
|
+
},
|
|
993
|
+
get portalTextColor() {
|
|
994
|
+
return self2.portalTextColor;
|
|
995
|
+
},
|
|
996
|
+
get portalPrimaryButtonTextColor() {
|
|
997
|
+
return self2.portalPrimaryButtonTextColor;
|
|
998
|
+
},
|
|
999
|
+
get portalBackgroundColor() {
|
|
1000
|
+
return self2.portalBackgroundColor;
|
|
1001
|
+
},
|
|
1002
|
+
get accountLinkInProgress() {
|
|
1003
|
+
return self2.accountLinkInProgress;
|
|
1002
1004
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
1033
|
-
}
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
// Create a dedicated interface for SessionManagementService
|
|
1008
|
+
getSessionManagementServiceInterface() {
|
|
1009
|
+
const self2 = this;
|
|
1010
|
+
return {
|
|
1011
|
+
displayModalError: this.displayModalError.bind(this),
|
|
1012
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
1013
|
+
initializeWorker: this.initializeWorker.bind(this),
|
|
1014
|
+
isPortal: this.isPortal.bind(this),
|
|
1015
|
+
getPartner: this.getPartner.bind(this),
|
|
1016
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
1017
|
+
platformUtils: this.platformUtils,
|
|
1018
|
+
ctx: this.ctx,
|
|
1019
|
+
get loginEncryptionKeyPair() {
|
|
1020
|
+
return self2.loginEncryptionKeyPair;
|
|
1021
|
+
},
|
|
1022
|
+
get partner() {
|
|
1023
|
+
return self2.partner;
|
|
1024
|
+
},
|
|
1025
|
+
get isWorkerInitialized() {
|
|
1026
|
+
return self2.isWorkerInitialized;
|
|
1027
|
+
},
|
|
1028
|
+
get isReady() {
|
|
1029
|
+
return self2.isReady;
|
|
1030
|
+
},
|
|
1031
|
+
isNoWalletConfig: this.isNoWalletConfig,
|
|
1032
|
+
get isSwitchingWallets() {
|
|
1033
|
+
return self2.isSwitchingWallets;
|
|
1034
1034
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
getStateMachineInterface() {
|
|
1038
|
+
const self2 = this;
|
|
1039
|
+
return {
|
|
1040
|
+
setup: this.setup.bind(this),
|
|
1041
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this),
|
|
1042
|
+
isPortal: this.isPortal.bind(this),
|
|
1043
|
+
setupAfterLogin: this.setupAfterLogin.bind(this),
|
|
1044
|
+
devLog: this.devLog.bind(this),
|
|
1045
|
+
authService: __privateGet(this, _authService),
|
|
1046
|
+
walletService: __privateGet(this, _walletService),
|
|
1047
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
1048
|
+
pollingService: __privateGet(this, _pollingService),
|
|
1049
|
+
externalWalletService: __privateGet(this, _externalWalletService),
|
|
1050
|
+
sessionManagementService: __privateGet(this, _sessionManagementService),
|
|
1051
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
1052
|
+
get isNoWalletConfig() {
|
|
1053
|
+
return self2.isNoWalletConfig;
|
|
1037
1054
|
}
|
|
1038
|
-
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
// Create a dedicated interface for ExternalWalletService
|
|
1058
|
+
getExternalWalletServiceInterface() {
|
|
1059
|
+
return {
|
|
1060
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
1061
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
1062
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this)
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
// Create a dedicated interface for PollingService
|
|
1066
|
+
getPollingServiceInterface() {
|
|
1067
|
+
const self2 = this;
|
|
1068
|
+
return {
|
|
1069
|
+
isPortal: this.isPortal.bind(this),
|
|
1070
|
+
devLog: this.devLog.bind(this),
|
|
1071
|
+
get popupWindow() {
|
|
1072
|
+
return self2.popupWindow;
|
|
1073
|
+
},
|
|
1074
|
+
set popupWindow(w) {
|
|
1075
|
+
self2.popupWindow = w;
|
|
1076
|
+
},
|
|
1077
|
+
platformUtils: this.platformUtils,
|
|
1078
|
+
ctx: this.ctx
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
touchSession(regenerate = false) {
|
|
1082
|
+
return __async(this, null, function* () {
|
|
1083
|
+
return __privateGet(this, _sessionManagementService).touchSession(regenerate);
|
|
1039
1084
|
});
|
|
1040
1085
|
}
|
|
1041
1086
|
getVerificationEmailProps() {
|
|
@@ -1068,7 +1113,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1068
1113
|
init() {
|
|
1069
1114
|
return __async(this, null, function* () {
|
|
1070
1115
|
var _a, _b;
|
|
1071
|
-
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1116
|
+
__privateGet(this, _authService).userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1072
1117
|
const storageAuthInfo = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
1073
1118
|
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1074
1119
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
@@ -1086,7 +1131,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1086
1131
|
};
|
|
1087
1132
|
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1088
1133
|
}
|
|
1089
|
-
|
|
1134
|
+
__privateGet(this, _authService).authInfo = authInfo;
|
|
1090
1135
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
1091
1136
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1092
1137
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -1110,8 +1155,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1110
1155
|
}, {}) : fromJson;
|
|
1111
1156
|
})();
|
|
1112
1157
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
1113
|
-
this.sessionCookie = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1114
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1158
|
+
__privateGet(this, _sessionManagementService).sessionCookie = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1159
|
+
if (Object.values(this.wallets).filter((w) => __privateGet(this, _walletService).isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1115
1160
|
this.findWalletId(void 0, { forbidPregen: true });
|
|
1116
1161
|
}
|
|
1117
1162
|
const loginEncryptionKey = yield this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
@@ -1128,12 +1173,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1128
1173
|
}
|
|
1129
1174
|
setAuth(_0) {
|
|
1130
1175
|
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
1131
|
-
|
|
1132
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
1133
|
-
if (!!userId) {
|
|
1134
|
-
yield this.setUserId(userId);
|
|
1135
|
-
}
|
|
1136
|
-
return __privateGet(this, _authInfo);
|
|
1176
|
+
return yield __privateGet(this, _authService).setAuth(auth, { extras, userId });
|
|
1137
1177
|
});
|
|
1138
1178
|
}
|
|
1139
1179
|
/**
|
|
@@ -1145,40 +1185,11 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1145
1185
|
this.setModalError(error);
|
|
1146
1186
|
}
|
|
1147
1187
|
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Handle specific touchSession errors with user-friendly messages
|
|
1150
|
-
* @private
|
|
1151
|
-
*/
|
|
1152
|
-
handleTouchSessionError(error) {
|
|
1153
|
-
const errorStr = String(error);
|
|
1154
|
-
const errorMessage = error instanceof Error ? error.message : "";
|
|
1155
|
-
if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
|
|
1156
|
-
const message = "Request rate limit reached. Please wait a couple of minutes and try again.";
|
|
1157
|
-
console.error(`[Para] ${message}`);
|
|
1158
|
-
this.displayModalError(message);
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
if (error.status === 403 && errorMessage.includes("origin not authorized")) {
|
|
1162
|
-
this.displayModalError(
|
|
1163
|
-
"The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
|
|
1164
|
-
);
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
1188
|
assertUserId({ allowGuestMode = false } = {}) {
|
|
1169
|
-
|
|
1170
|
-
throw new Error("no userId is set");
|
|
1171
|
-
}
|
|
1172
|
-
return this.userId;
|
|
1189
|
+
return __privateGet(this, _authService).assertUserId({ allowGuestMode });
|
|
1173
1190
|
}
|
|
1174
1191
|
assertIsAuthSet(allowed) {
|
|
1175
|
-
|
|
1176
|
-
throw new Error("auth is not set");
|
|
1177
|
-
}
|
|
1178
|
-
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
1179
|
-
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
1180
|
-
}
|
|
1181
|
-
return __privateGet(this, _authInfo);
|
|
1192
|
+
return __privateGet(this, _authService).assertIsAuthSet(allowed);
|
|
1182
1193
|
}
|
|
1183
1194
|
/**
|
|
1184
1195
|
* Sets the email associated with the `ParaCore` instance.
|
|
@@ -1186,7 +1197,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1186
1197
|
*/
|
|
1187
1198
|
setEmail(email) {
|
|
1188
1199
|
return __async(this, null, function* () {
|
|
1189
|
-
yield this.setAuth({ email });
|
|
1200
|
+
yield __privateGet(this, _authService).setAuth({ email });
|
|
1190
1201
|
});
|
|
1191
1202
|
}
|
|
1192
1203
|
/**
|
|
@@ -1195,7 +1206,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1195
1206
|
*/
|
|
1196
1207
|
setTelegramUserId(telegramUserId) {
|
|
1197
1208
|
return __async(this, null, function* () {
|
|
1198
|
-
yield this.setAuth({ telegramUserId });
|
|
1209
|
+
yield __privateGet(this, _authService).setAuth({ telegramUserId });
|
|
1199
1210
|
});
|
|
1200
1211
|
}
|
|
1201
1212
|
/**
|
|
@@ -1205,7 +1216,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1205
1216
|
*/
|
|
1206
1217
|
setPhoneNumber(phone, countryCode) {
|
|
1207
1218
|
return __async(this, null, function* () {
|
|
1208
|
-
yield this.setAuth({ phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) });
|
|
1219
|
+
yield __privateGet(this, _authService).setAuth({ phone: (0, import_utils2.formatPhoneNumber)(phone, countryCode) });
|
|
1209
1220
|
});
|
|
1210
1221
|
}
|
|
1211
1222
|
/**
|
|
@@ -1214,7 +1225,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1214
1225
|
*/
|
|
1215
1226
|
setFarcasterUsername(farcasterUsername) {
|
|
1216
1227
|
return __async(this, null, function* () {
|
|
1217
|
-
yield this.setAuth({ farcasterUsername });
|
|
1228
|
+
yield __privateGet(this, _authService).setAuth({ farcasterUsername });
|
|
1218
1229
|
});
|
|
1219
1230
|
}
|
|
1220
1231
|
/**
|
|
@@ -1224,75 +1235,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1224
1235
|
*/
|
|
1225
1236
|
setExternalWallet(externalWallet) {
|
|
1226
1237
|
return __async(this, null, function* () {
|
|
1227
|
-
|
|
1228
|
-
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1229
|
-
(acc, {
|
|
1230
|
-
partnerId: wPartnerId,
|
|
1231
|
-
address,
|
|
1232
|
-
type,
|
|
1233
|
-
provider,
|
|
1234
|
-
providerId,
|
|
1235
|
-
addressBech32,
|
|
1236
|
-
withFullParaAuth,
|
|
1237
|
-
isConnectionOnly,
|
|
1238
|
-
withVerification
|
|
1239
|
-
}) => {
|
|
1240
|
-
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1241
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1242
|
-
[address]: {
|
|
1243
|
-
id: address,
|
|
1244
|
-
partnerId,
|
|
1245
|
-
address: addressBech32 != null ? addressBech32 : address,
|
|
1246
|
-
type,
|
|
1247
|
-
name: provider,
|
|
1248
|
-
isExternal: true,
|
|
1249
|
-
isExternalWithParaAuth: withFullParaAuth,
|
|
1250
|
-
externalProviderId: providerId,
|
|
1251
|
-
signer: "",
|
|
1252
|
-
isExternalConnectionOnly: isConnectionOnly,
|
|
1253
|
-
isExternalWithVerification: withVerification
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
}
|
|
1257
|
-
return acc;
|
|
1258
|
-
},
|
|
1259
|
-
{}
|
|
1260
|
-
), this.setExternalWallets(this.externalWallets);
|
|
1261
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1238
|
+
return yield __privateGet(this, _externalWalletService).setExternalWallet({ externalWallet });
|
|
1262
1239
|
});
|
|
1263
1240
|
}
|
|
1264
1241
|
addExternalWallets(externalWallets) {
|
|
1265
1242
|
return __async(this, null, function* () {
|
|
1266
|
-
|
|
1267
|
-
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1268
|
-
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1269
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1270
|
-
[address]: wallet
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
return acc;
|
|
1274
|
-
}, {})), externalWallets.reduce(
|
|
1275
|
-
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
1276
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1277
|
-
[address]: {
|
|
1278
|
-
id: address,
|
|
1279
|
-
partnerId,
|
|
1280
|
-
address: addressBech32 != null ? addressBech32 : address,
|
|
1281
|
-
type,
|
|
1282
|
-
name: provider,
|
|
1283
|
-
isExternal: true,
|
|
1284
|
-
isExternalWithParaAuth: withFullParaAuth,
|
|
1285
|
-
externalProviderId: providerId,
|
|
1286
|
-
signer: "",
|
|
1287
|
-
isExternalConnectionOnly: isConnectionOnly,
|
|
1288
|
-
isExternalWithVerification: withVerification
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
},
|
|
1292
|
-
{}
|
|
1293
|
-
));
|
|
1294
|
-
this.setExternalWallets(this.externalWallets);
|
|
1295
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1243
|
+
return yield __privateGet(this, _externalWalletService).addExternalWallets({ externalWallets });
|
|
1296
1244
|
});
|
|
1297
1245
|
}
|
|
1298
1246
|
/**
|
|
@@ -1301,8 +1249,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1301
1249
|
*/
|
|
1302
1250
|
setUserId(userId) {
|
|
1303
1251
|
return __async(this, null, function* () {
|
|
1304
|
-
this.userId
|
|
1305
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_USER_ID, userId);
|
|
1252
|
+
return yield __privateGet(this, _authService).setUserId(userId);
|
|
1306
1253
|
});
|
|
1307
1254
|
}
|
|
1308
1255
|
/**
|
|
@@ -1311,12 +1258,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1311
1258
|
*/
|
|
1312
1259
|
setWallets(wallets) {
|
|
1313
1260
|
return __async(this, null, function* () {
|
|
1314
|
-
this.wallets
|
|
1315
|
-
if (this.platformUtils.secureStorage) {
|
|
1316
|
-
yield this.platformUtils.secureStorage.set(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1261
|
+
return yield __privateGet(this, _walletService).setWallets(wallets);
|
|
1320
1262
|
});
|
|
1321
1263
|
}
|
|
1322
1264
|
/**
|
|
@@ -1325,12 +1267,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1325
1267
|
*/
|
|
1326
1268
|
setExternalWallets(externalWallets) {
|
|
1327
1269
|
return __async(this, null, function* () {
|
|
1328
|
-
|
|
1329
|
-
this.externalWallets = externalWallets(this.externalWallets);
|
|
1330
|
-
} else {
|
|
1331
|
-
this.externalWallets = externalWallets;
|
|
1332
|
-
}
|
|
1333
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(this.externalWallets));
|
|
1270
|
+
return yield __privateGet(this, _externalWalletService).setExternalWallets({ externalWallets });
|
|
1334
1271
|
});
|
|
1335
1272
|
}
|
|
1336
1273
|
/**
|
|
@@ -1357,51 +1294,36 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1357
1294
|
* @returns - userId associated with the `ParaCore` instance.
|
|
1358
1295
|
*/
|
|
1359
1296
|
getUserId() {
|
|
1360
|
-
|
|
1297
|
+
var _a;
|
|
1298
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.userId;
|
|
1361
1299
|
}
|
|
1362
1300
|
getAuthInfo() {
|
|
1363
|
-
|
|
1301
|
+
var _a;
|
|
1302
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.authInfo;
|
|
1364
1303
|
}
|
|
1365
1304
|
/**
|
|
1366
1305
|
* Gets the email associated with the `ParaCore` instance.
|
|
1367
1306
|
* @returns - email associated with the `ParaCore` instance.
|
|
1368
1307
|
*/
|
|
1369
1308
|
getEmail() {
|
|
1370
|
-
|
|
1309
|
+
var _a;
|
|
1310
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.email;
|
|
1371
1311
|
}
|
|
1372
1312
|
/**
|
|
1373
1313
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
1374
1314
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
1375
1315
|
*/
|
|
1376
1316
|
getPhoneNumber() {
|
|
1377
|
-
|
|
1317
|
+
var _a;
|
|
1318
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.phone;
|
|
1378
1319
|
}
|
|
1379
1320
|
/**
|
|
1380
1321
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
1381
1322
|
* @returns - farcaster username associated with the `ParaCore` instance.
|
|
1382
1323
|
*/
|
|
1383
1324
|
getFarcasterUsername() {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
setCurrentWalletIds(_0) {
|
|
1387
|
-
return __async(this, arguments, function* (currentWalletIds, {
|
|
1388
|
-
needsWallet = false,
|
|
1389
|
-
sessionLookupId,
|
|
1390
|
-
newDeviceSessionLookupId
|
|
1391
|
-
} = {}) {
|
|
1392
|
-
this.currentWalletIds = currentWalletIds;
|
|
1393
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
1394
|
-
if (sessionLookupId) {
|
|
1395
|
-
yield this.ctx.client.setCurrentWalletIds(
|
|
1396
|
-
this.getUserId(),
|
|
1397
|
-
this.currentWalletIds,
|
|
1398
|
-
needsWallet,
|
|
1399
|
-
sessionLookupId,
|
|
1400
|
-
newDeviceSessionLookupId
|
|
1401
|
-
);
|
|
1402
|
-
}
|
|
1403
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
1404
|
-
});
|
|
1325
|
+
var _a;
|
|
1326
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.farcasterUsername;
|
|
1405
1327
|
}
|
|
1406
1328
|
/**
|
|
1407
1329
|
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
@@ -1419,29 +1341,6 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1419
1341
|
return accountMetadata;
|
|
1420
1342
|
});
|
|
1421
1343
|
}
|
|
1422
|
-
/**
|
|
1423
|
-
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
1424
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
1425
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
1426
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
1427
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
1428
|
-
*/
|
|
1429
|
-
findWalletId(walletId, filter = {}) {
|
|
1430
|
-
if (walletId) {
|
|
1431
|
-
this.assertIsValidWalletId(walletId, filter);
|
|
1432
|
-
} else {
|
|
1433
|
-
for (const id of [...this.currentWalletIdsUnique, ...Object.keys(this.wallets)]) {
|
|
1434
|
-
if (this.isWalletUsable(id, filter)) {
|
|
1435
|
-
walletId = id;
|
|
1436
|
-
break;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
if (!walletId) {
|
|
1440
|
-
throw new Error(`no valid wallet id found`);
|
|
1441
|
-
}
|
|
1442
|
-
}
|
|
1443
|
-
return walletId;
|
|
1444
|
-
}
|
|
1445
1344
|
/**
|
|
1446
1345
|
* Retrieves a wallet with the given address, if present.
|
|
1447
1346
|
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
@@ -1449,78 +1348,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1449
1348
|
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
1450
1349
|
* @returns {string} the wallet ID originally passed, or the one found.
|
|
1451
1350
|
*/
|
|
1452
|
-
findWalletByAddress(
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
const pregenWalletIds = Object.keys(this.wallets).filter(
|
|
1459
|
-
(id) => this.wallets[id].type === type && this.isPregenWalletClaimable(this.wallets[id])
|
|
1460
|
-
);
|
|
1461
|
-
[...walletIds, ...pregenWalletIds].forEach((id) => {
|
|
1462
|
-
if (address.toLowerCase() === this.getDisplayAddress(id, { addressType: type }).toLowerCase()) {
|
|
1463
|
-
wallet = this.wallets[id];
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
});
|
|
1467
|
-
if (!wallet) {
|
|
1468
|
-
throw new Error(`wallet with address ${address} not found`);
|
|
1469
|
-
}
|
|
1470
|
-
this.assertIsValidWalletId(wallet.id, filter);
|
|
1471
|
-
return wallet;
|
|
1472
|
-
}
|
|
1473
|
-
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
1474
|
-
var _a, _c, _d;
|
|
1475
|
-
if (!this.isExternalWalletAuth) {
|
|
1476
|
-
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1477
|
-
return Object.values(this.externalWallets)[0];
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
1481
|
-
return this.externalWallets[idOrAddress];
|
|
1482
|
-
}
|
|
1483
|
-
try {
|
|
1484
|
-
const walletId = this.findWalletId(idOrAddress, filter);
|
|
1485
|
-
if (walletId && !!this.wallets[walletId]) {
|
|
1486
|
-
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
1487
|
-
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
1488
|
-
return __spreadProps(__spreadValues({}, wallet), {
|
|
1489
|
-
type
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
} catch (e) {
|
|
1493
|
-
return void 0;
|
|
1494
|
-
}
|
|
1351
|
+
findWalletByAddress(...params) {
|
|
1352
|
+
return __privateGet(this, _walletService).findWalletByAddress(...params);
|
|
1353
|
+
}
|
|
1354
|
+
findWallet(...params) {
|
|
1355
|
+
const [walletId, walletType, filters = {}] = params;
|
|
1356
|
+
return __privateGet(this, _walletService).findWallet(walletId, walletType, filters);
|
|
1495
1357
|
}
|
|
1496
1358
|
get availableWallets() {
|
|
1497
|
-
|
|
1498
|
-
return [
|
|
1499
|
-
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1500
|
-
const wallet = this.findWallet(id, type);
|
|
1501
|
-
if (!wallet) return null;
|
|
1502
|
-
const name = wallet.name;
|
|
1503
|
-
const address = this.getDisplayAddress(id, { addressType: type });
|
|
1504
|
-
const addressShort = this.getDisplayAddress(id, { addressType: type, truncate: true });
|
|
1505
|
-
return {
|
|
1506
|
-
id: wallet.id,
|
|
1507
|
-
partner: wallet.partner,
|
|
1508
|
-
type,
|
|
1509
|
-
address,
|
|
1510
|
-
name,
|
|
1511
|
-
addressShort,
|
|
1512
|
-
displayName: name != null ? name : addressShort,
|
|
1513
|
-
ensName: wallet.ensName,
|
|
1514
|
-
ensAvatar: wallet.ensAvatar
|
|
1515
|
-
};
|
|
1516
|
-
}).filter((obj) => obj !== null),
|
|
1517
|
-
...Object.values((_a = this.externalWallets) != null ? _a : {}).map((wallet) => {
|
|
1518
|
-
return __spreadProps(__spreadValues({}, wallet), {
|
|
1519
|
-
addressShort: (0, import_utils2.truncateAddress)(wallet.address, wallet.type, { prefix: this.cosmosPrefix }),
|
|
1520
|
-
displayName: wallet.externalProviderId
|
|
1521
|
-
});
|
|
1522
|
-
})
|
|
1523
|
-
];
|
|
1359
|
+
return __privateGet(this, _walletService).availableWallets;
|
|
1524
1360
|
}
|
|
1525
1361
|
/**
|
|
1526
1362
|
* Retrieves all usable wallets with the provided type (`'EVM' | 'COSMOS' | 'SOLANA'`)
|
|
@@ -1528,52 +1364,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1528
1364
|
* @returns {Wallet[]} an array of matching wallets.
|
|
1529
1365
|
*/
|
|
1530
1366
|
getWalletsByType(type) {
|
|
1531
|
-
return
|
|
1532
|
-
}
|
|
1533
|
-
assertIsValidWalletId(walletId, condition = {}) {
|
|
1534
|
-
this.isWalletUsable(walletId, condition, true);
|
|
1535
|
-
}
|
|
1536
|
-
assertIsValidWalletType(type, walletTypes) {
|
|
1537
|
-
return __async(this, null, function* () {
|
|
1538
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1539
|
-
if (!type || !import_user_management_client.WALLET_TYPES.includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1540
|
-
throw new Error(`wallet type ${type} is not supported`);
|
|
1541
|
-
}
|
|
1542
|
-
return type;
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
getMissingTypes() {
|
|
1546
|
-
return __async(this, null, function* () {
|
|
1547
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1548
|
-
return supportedWalletTypes.filter(
|
|
1549
|
-
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !import_utils2.WalletSchemeTypeMap[w.scheme][t])
|
|
1550
|
-
).map(({ type }) => type);
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
getTypesToCreate(types) {
|
|
1554
|
-
return __async(this, null, function* () {
|
|
1555
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1556
|
-
return (0, import_utils2.getSchemes)(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1557
|
-
switch (scheme) {
|
|
1558
|
-
case "ED25519":
|
|
1559
|
-
return "SOLANA";
|
|
1560
|
-
default:
|
|
1561
|
-
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
1562
|
-
}
|
|
1563
|
-
});
|
|
1564
|
-
});
|
|
1367
|
+
return __privateGet(this, _walletService).getWalletsByType(type);
|
|
1565
1368
|
}
|
|
1566
|
-
|
|
1369
|
+
getPartner(partnerId) {
|
|
1567
1370
|
return __async(this, null, function* () {
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
return portalUrl;
|
|
1571
|
-
} catch (e) {
|
|
1572
|
-
if (this.isPartnerOptional) {
|
|
1573
|
-
return void 0;
|
|
1574
|
-
}
|
|
1575
|
-
throw e;
|
|
1371
|
+
if (this.isPartnerOptional && !partnerId) {
|
|
1372
|
+
return void 0;
|
|
1576
1373
|
}
|
|
1374
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
1375
|
+
this.partner = res.data.partner;
|
|
1376
|
+
return this.partner;
|
|
1577
1377
|
});
|
|
1578
1378
|
}
|
|
1579
1379
|
/**
|
|
@@ -1583,7 +1383,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1583
1383
|
*/
|
|
1584
1384
|
getPortalURL(isLegacy) {
|
|
1585
1385
|
return __async(this, null, function* () {
|
|
1586
|
-
return
|
|
1386
|
+
return yield __privateGet(this, _portalUrlService).getPortalURL(isLegacy);
|
|
1587
1387
|
});
|
|
1588
1388
|
}
|
|
1589
1389
|
/**
|
|
@@ -1616,33 +1416,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1616
1416
|
*/
|
|
1617
1417
|
fetchWallets() {
|
|
1618
1418
|
return __async(this, null, function* () {
|
|
1619
|
-
|
|
1620
|
-
return res.data.wallets.filter(
|
|
1621
|
-
(wallet) => !!wallet.address && wallet.sharesPersisted && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported((0, import_utils2.entityToWallet)(wallet)))
|
|
1622
|
-
);
|
|
1419
|
+
return yield __privateGet(this, _walletService).fetchWallets();
|
|
1623
1420
|
});
|
|
1624
1421
|
}
|
|
1625
1422
|
populateWalletAddresses() {
|
|
1626
1423
|
return __async(this, null, function* () {
|
|
1627
|
-
|
|
1628
|
-
const wallets = res.data.wallets;
|
|
1629
|
-
wallets.forEach((entity) => {
|
|
1630
|
-
if (this.wallets[entity.id]) {
|
|
1631
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, (0, import_utils2.entityToWallet)(entity)), this.wallets[entity.id]);
|
|
1632
|
-
}
|
|
1633
|
-
});
|
|
1634
|
-
yield this.setWallets(this.wallets);
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
populatePregenWalletAddresses() {
|
|
1638
|
-
return __async(this, null, function* () {
|
|
1639
|
-
const res = yield this.getPregenWallets();
|
|
1640
|
-
res.forEach((entity) => {
|
|
1641
|
-
if (this.wallets[entity.id]) {
|
|
1642
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, (0, import_utils2.entityToWallet)(entity)), this.wallets[entity.id]);
|
|
1643
|
-
}
|
|
1644
|
-
});
|
|
1645
|
-
yield this.setWallets(this.wallets);
|
|
1424
|
+
return yield __privateGet(this, _walletService).populateWalletAddresses();
|
|
1646
1425
|
});
|
|
1647
1426
|
}
|
|
1648
1427
|
/**
|
|
@@ -1652,91 +1431,39 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1652
1431
|
* @param {TWalletType} opts.type type of external wallet to use for identification.
|
|
1653
1432
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1654
1433
|
*/
|
|
1655
|
-
loginExternalWallet(
|
|
1434
|
+
loginExternalWallet(params) {
|
|
1656
1435
|
return __async(this, null, function* () {
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
yield this.ctx.client.trackExternalWalletConnections({
|
|
1669
|
-
wallets: externalWallets.map((wallet) => ({
|
|
1670
|
-
address: wallet.address,
|
|
1671
|
-
type: wallet.type,
|
|
1672
|
-
provider: wallet.provider
|
|
1673
|
-
}))
|
|
1674
|
-
});
|
|
1675
|
-
} catch (err) {
|
|
1676
|
-
console.error("Error tracking external wallet connections:", err);
|
|
1677
|
-
}
|
|
1678
|
-
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1679
|
-
yield this.addExternalWallets(
|
|
1680
|
-
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1681
|
-
withFullParaAuth: false
|
|
1682
|
-
}))
|
|
1683
|
-
);
|
|
1684
|
-
return Promise.resolve({
|
|
1685
|
-
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
if (Array.isArray(externalWallet)) {
|
|
1689
|
-
throw new Error(
|
|
1690
|
-
"Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
|
|
1691
|
-
);
|
|
1692
|
-
}
|
|
1693
|
-
this.requireApiKey();
|
|
1694
|
-
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet, chainId, uri });
|
|
1695
|
-
if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
|
|
1696
|
-
yield this.touchSession(true);
|
|
1697
|
-
}
|
|
1698
|
-
if (externalWallet.withFullParaAuth) {
|
|
1699
|
-
yield this.ctx.client.sessionAddPortalVerification();
|
|
1700
|
-
}
|
|
1701
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1436
|
+
return yield __privateGet(this, _authService).loginExternalWallet(params);
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Connects to an external wallet & logs in to Para (if applicable).
|
|
1441
|
+
* @param {Object} params the params object
|
|
1442
|
+
* @param {Function} params.connect the function called to connect to the external wallet.
|
|
1443
|
+
*/
|
|
1444
|
+
connectExternalWallet(params) {
|
|
1445
|
+
return __async(this, null, function* () {
|
|
1446
|
+
return yield __privateGet(this, _authService).connectExternalWallet(params);
|
|
1702
1447
|
});
|
|
1703
1448
|
}
|
|
1704
1449
|
verifyExternalWallet(params) {
|
|
1705
1450
|
return __async(this, null, function* () {
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
signedMessage,
|
|
1718
|
-
cosmosPublicKeyHex,
|
|
1719
|
-
cosmosSigner
|
|
1720
|
-
});
|
|
1721
|
-
serverAuthState = _serverAuthState;
|
|
1722
|
-
urlOptions = rest;
|
|
1723
|
-
}
|
|
1724
|
-
if (serverAuthState.stage === "login" && ((_c = serverAuthState.loginAuthMethods) == null ? void 0 : _c.includes(import_user_management_client.AuthMethod.PIN))) {
|
|
1725
|
-
const { sessionLookupId } = yield this.touchSession();
|
|
1726
|
-
return yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1727
|
-
}
|
|
1728
|
-
let state;
|
|
1729
|
-
try {
|
|
1730
|
-
state = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1731
|
-
} catch (err) {
|
|
1732
|
-
console.error("Error prepping state:", err);
|
|
1733
|
-
}
|
|
1734
|
-
return state;
|
|
1451
|
+
return yield __privateGet(this, _authService).verifyExternalWallet(params);
|
|
1452
|
+
});
|
|
1453
|
+
}
|
|
1454
|
+
retryVerifyExternalWallet() {
|
|
1455
|
+
return __async(this, null, function* () {
|
|
1456
|
+
return yield __privateGet(this, _authService).retryVerifyExternalWallet();
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
signExternalWalletVerification(params) {
|
|
1460
|
+
return __async(this, null, function* () {
|
|
1461
|
+
return yield __privateGet(this, _authService).signExternalWalletVerification(params);
|
|
1735
1462
|
});
|
|
1736
1463
|
}
|
|
1737
1464
|
verifyExternalWalletLink(opts) {
|
|
1738
1465
|
return __async(this, null, function* () {
|
|
1739
|
-
const accountLinkInProgress =
|
|
1466
|
+
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
|
|
1740
1467
|
if (!accountLinkInProgress.externalWallet) {
|
|
1741
1468
|
throw new Error("no external wallet account link in progress");
|
|
1742
1469
|
}
|
|
@@ -1754,13 +1481,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1754
1481
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1755
1482
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1756
1483
|
*/
|
|
1757
|
-
verifyTelegramProcess(
|
|
1484
|
+
verifyTelegramProcess(_a) {
|
|
1758
1485
|
return __async(this, null, function* () {
|
|
1759
|
-
var
|
|
1486
|
+
var _b = _a, {
|
|
1760
1487
|
serverAuthState: optsServerAuthState,
|
|
1761
1488
|
telegramAuthResponse,
|
|
1762
1489
|
isLinkAccount
|
|
1763
|
-
} =
|
|
1490
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
1764
1491
|
"serverAuthState",
|
|
1765
1492
|
"telegramAuthResponse",
|
|
1766
1493
|
"isLinkAccount"
|
|
@@ -1768,12 +1495,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1768
1495
|
try {
|
|
1769
1496
|
switch (isLinkAccount) {
|
|
1770
1497
|
case false: {
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
const { sessionLookupId } = yield this.touchSession();
|
|
1776
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1498
|
+
return yield __privateGet(this, _authService).verifyTelegram(__spreadValues({
|
|
1499
|
+
serverAuthState: optsServerAuthState,
|
|
1500
|
+
telegramAuthResponse
|
|
1501
|
+
}, urlOptions));
|
|
1777
1502
|
}
|
|
1778
1503
|
case true: {
|
|
1779
1504
|
if (!telegramAuthResponse) {
|
|
@@ -1793,9 +1518,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1793
1518
|
}
|
|
1794
1519
|
});
|
|
1795
1520
|
}
|
|
1796
|
-
verifyTelegram(
|
|
1521
|
+
verifyTelegram(params) {
|
|
1797
1522
|
return __async(this, null, function* () {
|
|
1798
|
-
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({},
|
|
1523
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
1799
1524
|
});
|
|
1800
1525
|
}
|
|
1801
1526
|
verifyTelegramLink(opts) {
|
|
@@ -1847,35 +1572,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1847
1572
|
* Resend a verification email for the current user.
|
|
1848
1573
|
*/
|
|
1849
1574
|
resendVerificationCode(_0) {
|
|
1850
|
-
return __async(this, arguments, function* ({
|
|
1851
|
-
type: reason
|
|
1852
|
-
}) {
|
|
1853
|
-
let type, linkedAccountId;
|
|
1854
|
-
switch (reason) {
|
|
1855
|
-
case "SIGNUP":
|
|
1856
|
-
case "LOGIN":
|
|
1857
|
-
{
|
|
1858
|
-
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1859
|
-
type = authInfo.authType.toUpperCase();
|
|
1860
|
-
}
|
|
1861
|
-
break;
|
|
1862
|
-
case "LINK_ACCOUNT":
|
|
1863
|
-
{
|
|
1864
|
-
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
|
|
1865
|
-
linkedAccountId = accountLinkInProgress.id;
|
|
1866
|
-
type = accountLinkInProgress.type;
|
|
1867
|
-
}
|
|
1868
|
-
break;
|
|
1869
|
-
}
|
|
1870
|
-
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1871
|
-
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1872
|
-
throw new Error("invalid auth type for verification code");
|
|
1873
|
-
}
|
|
1874
|
-
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
1875
|
-
userId,
|
|
1876
|
-
type,
|
|
1877
|
-
linkedAccountId
|
|
1878
|
-
}, this.getVerificationEmailProps()));
|
|
1575
|
+
return __async(this, arguments, function* ({ type: reason = "SIGNUP" }) {
|
|
1576
|
+
return yield __privateGet(this, _authService).resendVerificationCode({ type: reason });
|
|
1879
1577
|
});
|
|
1880
1578
|
}
|
|
1881
1579
|
/**
|
|
@@ -1884,18 +1582,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1884
1582
|
*/
|
|
1885
1583
|
isSessionActive() {
|
|
1886
1584
|
return __async(this, null, function* () {
|
|
1887
|
-
|
|
1888
|
-
return true;
|
|
1889
|
-
}
|
|
1890
|
-
const { isAuthenticated, verifiedExternalWalletAddresses } = yield this.touchSession();
|
|
1891
|
-
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1892
|
-
if (!verifiedExternalWalletAddresses) {
|
|
1893
|
-
return false;
|
|
1894
|
-
}
|
|
1895
|
-
const externalAddresses = Object.values(this.externalWallets).map((w) => w.id);
|
|
1896
|
-
return externalAddresses.every((address) => verifiedExternalWalletAddresses.includes(address));
|
|
1897
|
-
}
|
|
1898
|
-
return !!isAuthenticated;
|
|
1585
|
+
return yield __privateGet(this, _sessionManagementService).isSessionActive();
|
|
1899
1586
|
});
|
|
1900
1587
|
}
|
|
1901
1588
|
/**
|
|
@@ -1904,51 +1591,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1904
1591
|
**/
|
|
1905
1592
|
isFullyLoggedIn() {
|
|
1906
1593
|
return __async(this, null, function* () {
|
|
1907
|
-
|
|
1908
|
-
if (!this.isReady) {
|
|
1909
|
-
yield this.ready();
|
|
1910
|
-
}
|
|
1911
|
-
return true;
|
|
1912
|
-
}
|
|
1913
|
-
if (this.isGuestMode) {
|
|
1914
|
-
return true;
|
|
1915
|
-
}
|
|
1916
|
-
const isSessionActive = yield this.isSessionActive();
|
|
1917
|
-
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1918
|
-
return isSessionActive;
|
|
1919
|
-
}
|
|
1920
|
-
if (this.isSwitchingWallets) {
|
|
1921
|
-
return isSessionActive;
|
|
1922
|
-
}
|
|
1923
|
-
if (!isSessionActive) {
|
|
1924
|
-
return false;
|
|
1925
|
-
}
|
|
1926
|
-
if (this.isNoWalletConfig) {
|
|
1927
|
-
return true;
|
|
1928
|
-
}
|
|
1929
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1930
|
-
const requiredWalletTypes = supportedWalletTypes.filter(({ optional }) => !optional);
|
|
1931
|
-
for (const { type } of requiredWalletTypes) {
|
|
1932
|
-
const hasWalletForType = this.currentWalletIdsArray.some(([walletId, walletType]) => {
|
|
1933
|
-
try {
|
|
1934
|
-
const wallet = this.wallets[walletId];
|
|
1935
|
-
return wallet && walletType === type && typeof wallet.address === "string";
|
|
1936
|
-
} catch (e) {
|
|
1937
|
-
return false;
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
if (!hasWalletForType) {
|
|
1941
|
-
return false;
|
|
1942
|
-
}
|
|
1943
|
-
}
|
|
1944
|
-
return true;
|
|
1594
|
+
return yield __privateGet(this, _sessionManagementService).isFullyLoggedIn();
|
|
1945
1595
|
});
|
|
1946
1596
|
}
|
|
1947
1597
|
get isGuestMode() {
|
|
1948
|
-
|
|
1598
|
+
var _a;
|
|
1599
|
+
return ((_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.guestWalletIdsArray.length) > 0 && Object.values(this.wallets).every(
|
|
1949
1600
|
({ userId, partnerId }) => {
|
|
1950
|
-
var
|
|
1951
|
-
return partnerId === ((
|
|
1601
|
+
var _a2;
|
|
1602
|
+
return partnerId === ((_a2 = this.partner) == null ? void 0 : _a2.id) && (!userId || userId !== this.userId);
|
|
1952
1603
|
}
|
|
1953
1604
|
);
|
|
1954
1605
|
}
|
|
@@ -1978,30 +1629,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1978
1629
|
*/
|
|
1979
1630
|
supportedUserAuthMethods() {
|
|
1980
1631
|
return __async(this, null, function* () {
|
|
1981
|
-
yield this.
|
|
1982
|
-
const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
|
|
1983
|
-
this.authInfo.auth
|
|
1984
|
-
);
|
|
1985
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
1986
|
-
for (const type of supportedAuthMethods) {
|
|
1987
|
-
switch (type) {
|
|
1988
|
-
case "PASSWORD":
|
|
1989
|
-
if (hasPasswordWithoutPIN) {
|
|
1990
|
-
authMethods.add(import_user_management_client.AuthMethod.PASSWORD);
|
|
1991
|
-
}
|
|
1992
|
-
break;
|
|
1993
|
-
case "PASSKEY":
|
|
1994
|
-
authMethods.add(import_user_management_client.AuthMethod.PASSKEY);
|
|
1995
|
-
break;
|
|
1996
|
-
case "PIN":
|
|
1997
|
-
authMethods.add(import_user_management_client.AuthMethod.PIN);
|
|
1998
|
-
break;
|
|
1999
|
-
case "BASIC_LOGIN":
|
|
2000
|
-
authMethods.add(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
2001
|
-
break;
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
return authMethods;
|
|
1632
|
+
return yield __privateGet(this, _authService).supportedUserAuthMethods();
|
|
2005
1633
|
});
|
|
2006
1634
|
}
|
|
2007
1635
|
/**
|
|
@@ -2018,94 +1646,14 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2018
1646
|
/**
|
|
2019
1647
|
* Waits for the session to be active.
|
|
2020
1648
|
**/
|
|
2021
|
-
waitForSignup(
|
|
2022
|
-
return __async(this,
|
|
2023
|
-
|
|
2024
|
-
onCancel,
|
|
2025
|
-
onPoll
|
|
2026
|
-
}) {
|
|
2027
|
-
const startedAt = Date.now();
|
|
2028
|
-
return new Promise((resolve, reject) => {
|
|
2029
|
-
(() => __async(this, null, function* () {
|
|
2030
|
-
yield this.touchSession();
|
|
2031
|
-
if (!this.isExternalWalletAuth) {
|
|
2032
|
-
this.externalWallets = {};
|
|
2033
|
-
}
|
|
2034
|
-
while (true) {
|
|
2035
|
-
try {
|
|
2036
|
-
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
2037
|
-
onCancel == null ? void 0 : onCancel();
|
|
2038
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
2039
|
-
return reject("canceled");
|
|
2040
|
-
}
|
|
2041
|
-
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2042
|
-
if (yield this.isSessionActive()) {
|
|
2043
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2044
|
-
return resolve(true);
|
|
2045
|
-
}
|
|
2046
|
-
onPoll == null ? void 0 : onPoll();
|
|
2047
|
-
} catch (err) {
|
|
2048
|
-
console.error(err);
|
|
2049
|
-
onPoll == null ? void 0 : onPoll();
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
}))();
|
|
2053
|
-
});
|
|
1649
|
+
waitForSignup(params) {
|
|
1650
|
+
return __async(this, null, function* () {
|
|
1651
|
+
return yield __privateGet(this, _authService).waitForSignup(params);
|
|
2054
1652
|
});
|
|
2055
1653
|
}
|
|
2056
|
-
waitForWalletCreation() {
|
|
2057
|
-
return __async(this,
|
|
2058
|
-
|
|
2059
|
-
onCancel
|
|
2060
|
-
} = {}) {
|
|
2061
|
-
yield this.waitForSignup({ isCanceled, onCancel });
|
|
2062
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2063
|
-
const pregenWallets = yield this.getPregenWallets();
|
|
2064
|
-
let recoverySecret, walletIds = {};
|
|
2065
|
-
if (pregenWallets.length > 0) {
|
|
2066
|
-
let shares = [];
|
|
2067
|
-
try {
|
|
2068
|
-
shares = yield this.ctx.enclaveClient.getPregenShares({
|
|
2069
|
-
userId: this.userId,
|
|
2070
|
-
walletIds: pregenWallets.map((w) => w.id),
|
|
2071
|
-
partnerId: pregenWallets[0].partnerId
|
|
2072
|
-
});
|
|
2073
|
-
for (const share of shares) {
|
|
2074
|
-
const wallet = pregenWallets.find((w) => w.id === share.walletId);
|
|
2075
|
-
if (wallet) {
|
|
2076
|
-
this.wallets[wallet.id] = {
|
|
2077
|
-
id: wallet.id,
|
|
2078
|
-
address: wallet.address,
|
|
2079
|
-
scheme: wallet.scheme,
|
|
2080
|
-
type: wallet.type,
|
|
2081
|
-
partnerId: wallet.partnerId,
|
|
2082
|
-
isPregen: wallet.isPregen,
|
|
2083
|
-
pregenIdentifier: wallet.pregenIdentifier,
|
|
2084
|
-
pregenIdentifierType: wallet.pregenIdentifierType,
|
|
2085
|
-
signer: share.signer,
|
|
2086
|
-
createdAt: String(wallet.createdAt)
|
|
2087
|
-
};
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
} catch (err) {
|
|
2091
|
-
console.warn("[waitForWalletCreation] Failed to fetch pregen shares:", err);
|
|
2092
|
-
}
|
|
2093
|
-
if (shares.length > 0) {
|
|
2094
|
-
recoverySecret = yield this.claimPregenWallets();
|
|
2095
|
-
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
2096
|
-
var _a;
|
|
2097
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
2098
|
-
[type]: [(_a = pregenWallets.find((w) => !!import_utils2.WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2099
|
-
});
|
|
2100
|
-
}, {});
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
const created = yield this.createWalletPerType();
|
|
2104
|
-
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2105
|
-
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2106
|
-
const resp = { walletIds, recoverySecret };
|
|
2107
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2108
|
-
return resp;
|
|
1654
|
+
waitForWalletCreation(params) {
|
|
1655
|
+
return __async(this, null, function* () {
|
|
1656
|
+
return yield __privateGet(this, _authService).waitForWalletCreation(params);
|
|
2109
1657
|
});
|
|
2110
1658
|
}
|
|
2111
1659
|
/**
|
|
@@ -2125,35 +1673,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2125
1673
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2126
1674
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2127
1675
|
*/
|
|
2128
|
-
verifyFarcasterProcess(
|
|
1676
|
+
verifyFarcasterProcess(_c) {
|
|
2129
1677
|
return __async(this, null, function* () {
|
|
2130
|
-
var
|
|
1678
|
+
var _d = _c, {
|
|
2131
1679
|
isCanceled = () => false,
|
|
2132
1680
|
onConnectUri,
|
|
2133
1681
|
onCancel,
|
|
2134
|
-
onPoll,
|
|
2135
1682
|
isLinkAccount,
|
|
2136
1683
|
serverAuthState: optsServerAuthState
|
|
2137
|
-
} =
|
|
1684
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
2138
1685
|
"isCanceled",
|
|
2139
1686
|
"onConnectUri",
|
|
2140
1687
|
"onCancel",
|
|
2141
|
-
"onPoll",
|
|
2142
1688
|
"isLinkAccount",
|
|
2143
1689
|
"serverAuthState"
|
|
2144
1690
|
]);
|
|
2145
|
-
if (
|
|
2146
|
-
const
|
|
2147
|
-
|
|
1691
|
+
if (onConnectUri) {
|
|
1692
|
+
const connectUri = yield this.getFarcasterConnectUri();
|
|
1693
|
+
onConnectUri(connectUri);
|
|
1694
|
+
}
|
|
1695
|
+
if (!isLinkAccount) {
|
|
1696
|
+
return yield __privateGet(this, _authService).verifyFarcaster(__spreadValues({
|
|
1697
|
+
serverAuthState: optsServerAuthState
|
|
1698
|
+
}, urlOptions));
|
|
2148
1699
|
}
|
|
2149
1700
|
let accountLinkInProgress;
|
|
2150
1701
|
if (isLinkAccount) {
|
|
2151
1702
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
2152
1703
|
}
|
|
2153
|
-
if (onConnectUri) {
|
|
2154
|
-
const connectUri = yield this.getFarcasterConnectUri();
|
|
2155
|
-
onConnectUri(connectUri);
|
|
2156
|
-
}
|
|
2157
1704
|
return new Promise((resolve, reject) => {
|
|
2158
1705
|
(() => __async(this, null, function* () {
|
|
2159
1706
|
const startedAt = Date.now();
|
|
@@ -2164,27 +1711,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2164
1711
|
return reject("CANCELED");
|
|
2165
1712
|
}
|
|
2166
1713
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2173
|
-
return resolve(authState);
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
break;
|
|
2177
|
-
case true: {
|
|
2178
|
-
const result = yield this.verifyLink({
|
|
2179
|
-
accountLinkInProgress
|
|
2180
|
-
});
|
|
2181
|
-
if ("isConflict" in result) {
|
|
2182
|
-
throw new Error(import_types.AccountLinkError.Conflict);
|
|
2183
|
-
}
|
|
2184
|
-
return resolve(result);
|
|
2185
|
-
}
|
|
1714
|
+
const result = yield this.verifyLink({
|
|
1715
|
+
accountLinkInProgress
|
|
1716
|
+
});
|
|
1717
|
+
if ("isConflict" in result) {
|
|
1718
|
+
throw new Error(import_types.AccountLinkError.Conflict);
|
|
2186
1719
|
}
|
|
2187
|
-
|
|
1720
|
+
return resolve(result);
|
|
2188
1721
|
} catch (e) {
|
|
2189
1722
|
if (!isLinkAccount || e.message === import_types.AccountLinkError.Conflict) {
|
|
2190
1723
|
return reject(e.message);
|
|
@@ -2195,9 +1728,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2195
1728
|
});
|
|
2196
1729
|
});
|
|
2197
1730
|
}
|
|
2198
|
-
verifyFarcaster(
|
|
1731
|
+
verifyFarcaster(params) {
|
|
2199
1732
|
return __async(this, null, function* () {
|
|
2200
|
-
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({},
|
|
1733
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
2201
1734
|
});
|
|
2202
1735
|
}
|
|
2203
1736
|
verifyFarcasterLink(opts) {
|
|
@@ -2205,11 +1738,17 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2205
1738
|
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
2206
1739
|
});
|
|
2207
1740
|
}
|
|
2208
|
-
|
|
1741
|
+
/**
|
|
1742
|
+
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1743
|
+
*
|
|
1744
|
+
* @param {Object} opts the options object
|
|
1745
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1746
|
+
* @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
|
|
1747
|
+
* @returns {string} the URL for the user to log in with OAuth.
|
|
1748
|
+
*/
|
|
1749
|
+
getOAuthUrl(params) {
|
|
2209
1750
|
return __async(this, null, function* () {
|
|
2210
|
-
|
|
2211
|
-
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
2212
|
-
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
1751
|
+
return yield __privateGet(this, _portalUrlService).getOAuthUrl(params);
|
|
2213
1752
|
});
|
|
2214
1753
|
}
|
|
2215
1754
|
/**
|
|
@@ -2220,27 +1759,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2220
1759
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2221
1760
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
2222
1761
|
*/
|
|
2223
|
-
verifyOAuthProcess(
|
|
1762
|
+
verifyOAuthProcess(params) {
|
|
2224
1763
|
return __async(this, null, function* () {
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
onCancel,
|
|
2230
|
-
onPoll,
|
|
2231
|
-
onOAuthUrl,
|
|
2232
|
-
onOAuthPopup,
|
|
2233
|
-
isLinkAccount
|
|
2234
|
-
} = _h, urlOptions = __objRest(_h, [
|
|
2235
|
-
"method",
|
|
2236
|
-
"appScheme",
|
|
2237
|
-
"isCanceled",
|
|
2238
|
-
"onCancel",
|
|
2239
|
-
"onPoll",
|
|
2240
|
-
"onOAuthUrl",
|
|
2241
|
-
"onOAuthPopup",
|
|
2242
|
-
"isLinkAccount"
|
|
2243
|
-
]);
|
|
1764
|
+
if (!params.isLinkAccount) {
|
|
1765
|
+
return yield __privateGet(this, _authService).verifyOAuthProcess(params);
|
|
1766
|
+
}
|
|
1767
|
+
const { method, appScheme, isCanceled = () => false, onCancel, onPoll, onOAuthUrl, onOAuthPopup } = params;
|
|
2244
1768
|
if (onOAuthPopup) {
|
|
2245
1769
|
try {
|
|
2246
1770
|
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.OAUTH });
|
|
@@ -2250,13 +1774,14 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2250
1774
|
}
|
|
2251
1775
|
let sessionLookupId, accountLinkInProgress;
|
|
2252
1776
|
if (onOAuthUrl || onOAuthPopup) {
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
1777
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1778
|
+
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1779
|
+
const oAuthUrl = yield __privateGet(this, _portalUrlService).getOAuthUrl({
|
|
1780
|
+
method,
|
|
1781
|
+
appScheme,
|
|
1782
|
+
sessionLookupId,
|
|
1783
|
+
accountLinkInProgress
|
|
1784
|
+
});
|
|
2260
1785
|
switch (true) {
|
|
2261
1786
|
case !!onOAuthUrl: {
|
|
2262
1787
|
onOAuthUrl(oAuthUrl);
|
|
@@ -2281,24 +1806,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2281
1806
|
return reject(import_types.AccountLinkError.Canceled);
|
|
2282
1807
|
}
|
|
2283
1808
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
{
|
|
2287
|
-
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
2288
|
-
if ((0, import_utils2.isServerAuthState)(serverAuthState)) {
|
|
2289
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
2290
|
-
return resolve(authState);
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
break;
|
|
2294
|
-
case true: {
|
|
2295
|
-
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
2296
|
-
return resolve(accounts);
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
onPoll == null ? void 0 : onPoll();
|
|
1809
|
+
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
1810
|
+
return resolve(accounts);
|
|
2300
1811
|
} catch (err) {
|
|
2301
|
-
if (
|
|
1812
|
+
if (err.message === import_types.AccountLinkError.Conflict) {
|
|
2302
1813
|
return reject(err.message);
|
|
2303
1814
|
}
|
|
2304
1815
|
onPoll == null ? void 0 : onPoll();
|
|
@@ -2308,9 +1819,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2308
1819
|
});
|
|
2309
1820
|
});
|
|
2310
1821
|
}
|
|
2311
|
-
verifyOAuth(
|
|
1822
|
+
verifyOAuth(params) {
|
|
2312
1823
|
return __async(this, null, function* () {
|
|
2313
|
-
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({},
|
|
1824
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
2314
1825
|
});
|
|
2315
1826
|
}
|
|
2316
1827
|
verifyOAuthLink(opts) {
|
|
@@ -2326,9 +1837,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2326
1837
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2327
1838
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2328
1839
|
**/
|
|
2329
|
-
waitForLogin(
|
|
1840
|
+
waitForLogin(params) {
|
|
2330
1841
|
return __async(this, null, function* () {
|
|
2331
|
-
return yield
|
|
1842
|
+
return yield __privateGet(this, _authService).waitForLogin(params);
|
|
2332
1843
|
});
|
|
2333
1844
|
}
|
|
2334
1845
|
waitForWalletSwitching(args) {
|
|
@@ -2344,7 +1855,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2344
1855
|
*/
|
|
2345
1856
|
getSwitchWalletsUrl() {
|
|
2346
1857
|
return __async(this, null, function* () {
|
|
2347
|
-
const
|
|
1858
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
1859
|
+
const url = yield this.constructPortalUrl("switchWallets", {
|
|
1860
|
+
useLegacyUrl: authMethods.has(import_user_management_client.AuthMethod.PASSKEY)
|
|
1861
|
+
});
|
|
2348
1862
|
return url;
|
|
2349
1863
|
});
|
|
2350
1864
|
}
|
|
@@ -2357,32 +1871,20 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2357
1871
|
* @returns a URL for the user to reauthenticate.
|
|
2358
1872
|
**/
|
|
2359
1873
|
refreshSession() {
|
|
2360
|
-
return __async(this, arguments, function* ({
|
|
2361
|
-
|
|
2362
|
-
} = {}) {
|
|
2363
|
-
const { sessionId } = yield this.touchSession(true);
|
|
2364
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2365
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2366
|
-
}
|
|
2367
|
-
const link = yield this.getLoginUrl({
|
|
2368
|
-
sessionId
|
|
2369
|
-
});
|
|
2370
|
-
if (shouldOpenPopup) {
|
|
2371
|
-
yield this.platformUtils.openPopup(link);
|
|
2372
|
-
}
|
|
2373
|
-
return link;
|
|
1874
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1875
|
+
return yield __privateGet(this, _sessionManagementService).refreshSession(params);
|
|
2374
1876
|
});
|
|
2375
1877
|
}
|
|
2376
1878
|
/**
|
|
2377
1879
|
* Call this method after login to ensure that the user ID is set
|
|
2378
1880
|
* internally.
|
|
2379
1881
|
**/
|
|
2380
|
-
userSetupAfterLogin() {
|
|
1882
|
+
userSetupAfterLogin(existingSession) {
|
|
2381
1883
|
return __async(this, null, function* () {
|
|
2382
|
-
const session = yield this.touchSession();
|
|
2383
|
-
yield this.setUserId(session.userId);
|
|
2384
|
-
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
2385
|
-
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
1884
|
+
const session = existingSession != null ? existingSession : yield this.touchSession();
|
|
1885
|
+
yield __privateGet(this, _authService).setUserId(session.userId);
|
|
1886
|
+
if (session.currentWalletIds && session.currentWalletIds !== __privateGet(this, _walletService).currentWalletIds)
|
|
1887
|
+
yield __privateGet(this, _walletService).setCurrentWalletIds(session.currentWalletIds, {
|
|
2386
1888
|
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
2387
1889
|
});
|
|
2388
1890
|
return session;
|
|
@@ -2395,9 +1897,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2395
1897
|
* @returns - transmission keyshares.
|
|
2396
1898
|
**/
|
|
2397
1899
|
getTransmissionKeyShares() {
|
|
2398
|
-
return __async(this, arguments, function* ({
|
|
2399
|
-
|
|
2400
|
-
|
|
1900
|
+
return __async(this, arguments, function* ({
|
|
1901
|
+
isForNewDevice = false,
|
|
1902
|
+
sessionLookupId: existingSessionLookupId
|
|
1903
|
+
} = {}) {
|
|
1904
|
+
const baseSessionLookupId = existingSessionLookupId != null ? existingSessionLookupId : (yield this.touchSession()).sessionLookupId;
|
|
1905
|
+
const sessionLookupId = isForNewDevice ? `${baseSessionLookupId}-new-device` : baseSessionLookupId;
|
|
2401
1906
|
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2402
1907
|
});
|
|
2403
1908
|
}
|
|
@@ -2411,111 +1916,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2411
1916
|
return __async(this, arguments, function* ({
|
|
2412
1917
|
temporaryShares,
|
|
2413
1918
|
skipSessionRefresh = false
|
|
2414
|
-
} = {}) {
|
|
2415
|
-
if (!temporaryShares) {
|
|
2416
|
-
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2417
|
-
}
|
|
2418
|
-
temporaryShares.forEach((share) => {
|
|
2419
|
-
const signer = (0, import_utils.decryptWithPrivateKey)(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
2420
|
-
this.wallets[share.walletId] = {
|
|
2421
|
-
id: share.walletId,
|
|
2422
|
-
signer
|
|
2423
|
-
};
|
|
2424
|
-
});
|
|
2425
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
2426
|
-
yield this.populateWalletAddresses();
|
|
2427
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
2428
|
-
});
|
|
2429
|
-
}
|
|
2430
|
-
/**
|
|
2431
|
-
* Distributes a new wallet recovery share.
|
|
2432
|
-
* @param {Object} opts the options object.
|
|
2433
|
-
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
2434
|
-
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
2435
|
-
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
2436
|
-
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2437
|
-
* @returns {string} the recovery share.
|
|
2438
|
-
**/
|
|
2439
|
-
distributeNewWalletShare(_0) {
|
|
2440
|
-
return __async(this, arguments, function* ({
|
|
2441
|
-
walletId,
|
|
2442
|
-
userShare,
|
|
2443
|
-
skipBiometricShareCreation = false,
|
|
2444
|
-
forceRefresh = false
|
|
2445
|
-
}) {
|
|
2446
|
-
let userSigner = userShare;
|
|
2447
|
-
if (!userSigner) {
|
|
2448
|
-
userSigner = this.wallets[walletId].signer;
|
|
2449
|
-
}
|
|
2450
|
-
const recoveryShare = skipBiometricShareCreation ? yield (0, import_recovery.sendRecoveryForShare)({
|
|
2451
|
-
ctx: this.ctx,
|
|
2452
|
-
userId: this.userId,
|
|
2453
|
-
walletId,
|
|
2454
|
-
userSigner,
|
|
2455
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2456
|
-
forceRefresh
|
|
2457
|
-
}) : yield (0, import_shareDistribution.distributeNewShare)({
|
|
2458
|
-
ctx: this.ctx,
|
|
2459
|
-
userId: this.userId,
|
|
2460
|
-
walletId,
|
|
2461
|
-
userShare: userSigner,
|
|
2462
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2463
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2464
|
-
walletScheme: this.wallets[walletId].scheme
|
|
2465
|
-
});
|
|
2466
|
-
return recoveryShare;
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
waitForWalletAddress(walletId) {
|
|
2470
|
-
return __async(this, null, function* () {
|
|
2471
|
-
let maxPolls = 0;
|
|
2472
|
-
while (true) {
|
|
2473
|
-
try {
|
|
2474
|
-
if (maxPolls === 10) {
|
|
2475
|
-
break;
|
|
2476
|
-
}
|
|
2477
|
-
++maxPolls;
|
|
2478
|
-
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
|
|
2479
|
-
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2480
|
-
if (wallet && wallet.address) {
|
|
2481
|
-
return;
|
|
2482
|
-
}
|
|
2483
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
2484
|
-
} catch (err) {
|
|
2485
|
-
console.error(err);
|
|
2486
|
-
}
|
|
1919
|
+
} = {}) {
|
|
1920
|
+
if (!temporaryShares) {
|
|
1921
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2487
1922
|
}
|
|
2488
|
-
|
|
1923
|
+
temporaryShares.forEach((share) => {
|
|
1924
|
+
const signer = (0, import_utils.decryptWithPrivateKey)(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
1925
|
+
this.wallets[share.walletId] = {
|
|
1926
|
+
id: share.walletId,
|
|
1927
|
+
signer
|
|
1928
|
+
};
|
|
1929
|
+
});
|
|
1930
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
1931
|
+
yield __privateGet(this, _walletService).populateWalletAddresses();
|
|
1932
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2489
1933
|
});
|
|
2490
1934
|
}
|
|
2491
1935
|
/**
|
|
2492
|
-
*
|
|
2493
|
-
*
|
|
2494
|
-
* @param
|
|
2495
|
-
* @param
|
|
2496
|
-
* @param
|
|
2497
|
-
* @
|
|
1936
|
+
* Distributes a new wallet recovery share.
|
|
1937
|
+
* @param {Object} opts the options object.
|
|
1938
|
+
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
1939
|
+
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
1940
|
+
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
1941
|
+
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
1942
|
+
* @returns {string} the recovery share.
|
|
2498
1943
|
**/
|
|
2499
|
-
|
|
1944
|
+
distributeNewWalletShare(params) {
|
|
2500
1945
|
return __async(this, null, function* () {
|
|
2501
|
-
|
|
2502
|
-
while (true) {
|
|
2503
|
-
try {
|
|
2504
|
-
if (maxPolls === 10) {
|
|
2505
|
-
break;
|
|
2506
|
-
}
|
|
2507
|
-
++maxPolls;
|
|
2508
|
-
const res = yield this.getPregenWallets();
|
|
2509
|
-
const wallet = res.find((w) => w.id === walletId);
|
|
2510
|
-
if (wallet && wallet.address) {
|
|
2511
|
-
return;
|
|
2512
|
-
}
|
|
2513
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
2514
|
-
} catch (err) {
|
|
2515
|
-
console.error(err);
|
|
2516
|
-
}
|
|
2517
|
-
}
|
|
2518
|
-
throw new Error("timed out waiting for wallet address");
|
|
1946
|
+
return yield __privateGet(this, _walletService).distributeNewWalletShare(params);
|
|
2519
1947
|
});
|
|
2520
1948
|
}
|
|
2521
1949
|
/**
|
|
@@ -2530,24 +1958,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2530
1958
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2531
1959
|
**/
|
|
2532
1960
|
createWalletPerType() {
|
|
2533
|
-
return __async(this, arguments, function* ({
|
|
2534
|
-
|
|
2535
|
-
types
|
|
2536
|
-
} = {}) {
|
|
2537
|
-
const wallets = [];
|
|
2538
|
-
const walletIds = {};
|
|
2539
|
-
let recoverySecret;
|
|
2540
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2541
|
-
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
2542
|
-
wallets.push(wallet);
|
|
2543
|
-
(0, import_utils2.getEquivalentTypes)(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
2544
|
-
walletIds[t] = [wallet.id];
|
|
2545
|
-
});
|
|
2546
|
-
if (recoveryShare) {
|
|
2547
|
-
recoverySecret = recoveryShare;
|
|
2548
|
-
}
|
|
2549
|
-
}
|
|
2550
|
-
return { wallets, walletIds, recoverySecret };
|
|
1961
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1962
|
+
return yield __privateGet(this, _walletService).createWalletPerType(params);
|
|
2551
1963
|
});
|
|
2552
1964
|
}
|
|
2553
1965
|
/**
|
|
@@ -2562,38 +1974,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2562
1974
|
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2563
1975
|
* @returns {Object} the new user share and recovery secret.
|
|
2564
1976
|
**/
|
|
2565
|
-
refreshShare(
|
|
2566
|
-
return __async(this,
|
|
2567
|
-
|
|
2568
|
-
share,
|
|
2569
|
-
oldPartnerId,
|
|
2570
|
-
newPartnerId,
|
|
2571
|
-
keyShareProtocolId,
|
|
2572
|
-
redistributeBackupEncryptedShares
|
|
2573
|
-
}) {
|
|
2574
|
-
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
2575
|
-
this.ctx,
|
|
2576
|
-
this.retrieveSessionCookie(),
|
|
2577
|
-
this.userId,
|
|
2578
|
-
walletId,
|
|
2579
|
-
share,
|
|
2580
|
-
oldPartnerId,
|
|
2581
|
-
newPartnerId,
|
|
2582
|
-
keyShareProtocolId
|
|
2583
|
-
);
|
|
2584
|
-
const recoverySecret = yield (0, import_shareDistribution.distributeNewShare)({
|
|
2585
|
-
ctx: this.ctx,
|
|
2586
|
-
userId: this.userId,
|
|
2587
|
-
walletId,
|
|
2588
|
-
userShare: signer,
|
|
2589
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2590
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2591
|
-
partnerId: newPartnerId,
|
|
2592
|
-
protocolId,
|
|
2593
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2594
|
-
walletScheme: this.wallets[walletId].scheme
|
|
2595
|
-
});
|
|
2596
|
-
return { signer, recoverySecret, protocolId };
|
|
1977
|
+
refreshShare(params) {
|
|
1978
|
+
return __async(this, null, function* () {
|
|
1979
|
+
return yield __privateGet(this, _walletService).refreshShare(params);
|
|
2597
1980
|
});
|
|
2598
1981
|
}
|
|
2599
1982
|
/**
|
|
@@ -2604,80 +1987,22 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2604
1987
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2605
1988
|
**/
|
|
2606
1989
|
createWallet() {
|
|
2607
|
-
return __async(this, arguments, function* ({
|
|
2608
|
-
|
|
2609
|
-
skipDistribute = false
|
|
2610
|
-
} = {}) {
|
|
2611
|
-
var _a, _b;
|
|
2612
|
-
this.requireApiKey();
|
|
2613
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2614
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
2615
|
-
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2616
|
-
);
|
|
2617
|
-
let signer;
|
|
2618
|
-
let wallet;
|
|
2619
|
-
let keygenRes;
|
|
2620
|
-
switch (walletType) {
|
|
2621
|
-
case "SOLANA": {
|
|
2622
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2623
|
-
this.ctx,
|
|
2624
|
-
this.userId,
|
|
2625
|
-
this.retrieveSessionCookie(),
|
|
2626
|
-
this.getBackupKitEmailProps()
|
|
2627
|
-
);
|
|
2628
|
-
break;
|
|
2629
|
-
}
|
|
2630
|
-
default: {
|
|
2631
|
-
keygenRes = yield this.platformUtils.keygen(
|
|
2632
|
-
this.ctx,
|
|
2633
|
-
this.userId,
|
|
2634
|
-
walletType,
|
|
2635
|
-
null,
|
|
2636
|
-
this.retrieveSessionCookie(),
|
|
2637
|
-
this.getBackupKitEmailProps()
|
|
2638
|
-
);
|
|
2639
|
-
break;
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
const walletId = keygenRes.walletId;
|
|
2643
|
-
const walletScheme = walletType === "SOLANA" ? "ED25519" : "DKLS";
|
|
2644
|
-
signer = keygenRes.signer;
|
|
2645
|
-
yield this.waitForWalletAddress(walletId);
|
|
2646
|
-
let recoveryShare = null;
|
|
2647
|
-
if (!skipDistribute) {
|
|
2648
|
-
recoveryShare = yield (0, import_shareDistribution.distributeNewShare)({
|
|
2649
|
-
ctx: this.ctx,
|
|
2650
|
-
userId: this.userId,
|
|
2651
|
-
walletId,
|
|
2652
|
-
userShare: signer,
|
|
2653
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2654
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2655
|
-
walletScheme
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
this.wallets[walletId] = {
|
|
2659
|
-
id: walletId,
|
|
2660
|
-
signer,
|
|
2661
|
-
scheme: walletScheme,
|
|
2662
|
-
type: walletType
|
|
2663
|
-
};
|
|
2664
|
-
wallet = this.wallets[walletId];
|
|
2665
|
-
yield this.populateWalletAddresses();
|
|
2666
|
-
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2667
|
-
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2668
|
-
}));
|
|
2669
|
-
const walletNoSigner = __spreadValues({}, wallet);
|
|
2670
|
-
delete walletNoSigner.signer;
|
|
2671
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.WALLET_CREATED, {
|
|
2672
|
-
wallet: walletNoSigner,
|
|
2673
|
-
recoverySecret: recoveryShare
|
|
2674
|
-
});
|
|
2675
|
-
return [wallet, recoveryShare];
|
|
1990
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1991
|
+
return yield __privateGet(this, _walletService).createWallet(params);
|
|
2676
1992
|
});
|
|
2677
1993
|
}
|
|
2678
|
-
|
|
1994
|
+
/**
|
|
1995
|
+
* Creates a new pregenerated wallet.
|
|
1996
|
+
*
|
|
1997
|
+
* @param {Object} opts the options object.
|
|
1998
|
+
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
1999
|
+
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
2000
|
+
* @param {TWalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
2001
|
+
* @returns {Wallet} the created wallet.
|
|
2002
|
+
**/
|
|
2003
|
+
createPregenWallet(params) {
|
|
2679
2004
|
return __async(this, null, function* () {
|
|
2680
|
-
return yield
|
|
2005
|
+
return yield __privateGet(this, _pregenWalletService).createPregenWallet(params);
|
|
2681
2006
|
});
|
|
2682
2007
|
}
|
|
2683
2008
|
/**
|
|
@@ -2690,17 +2015,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2690
2015
|
* @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2691
2016
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
2692
2017
|
**/
|
|
2693
|
-
createPregenWalletPerType(
|
|
2694
|
-
return __async(this,
|
|
2695
|
-
|
|
2696
|
-
pregenId
|
|
2697
|
-
}) {
|
|
2698
|
-
const wallets = [];
|
|
2699
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2700
|
-
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
2701
|
-
wallets.push(wallet);
|
|
2702
|
-
}
|
|
2703
|
-
return wallets;
|
|
2018
|
+
createPregenWalletPerType(params) {
|
|
2019
|
+
return __async(this, null, function* () {
|
|
2020
|
+
return yield __privateGet(this, _pregenWalletService).createPregenWalletPerType(params);
|
|
2704
2021
|
});
|
|
2705
2022
|
}
|
|
2706
2023
|
/**
|
|
@@ -2711,70 +2028,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2711
2028
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2712
2029
|
**/
|
|
2713
2030
|
claimPregenWallets() {
|
|
2714
|
-
return __async(this, arguments, function* ({
|
|
2715
|
-
|
|
2716
|
-
} = {}) {
|
|
2717
|
-
var _a;
|
|
2718
|
-
this.requireApiKey();
|
|
2719
|
-
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
2720
|
-
if (pregenWallets.length === 0) {
|
|
2721
|
-
return void 0;
|
|
2722
|
-
}
|
|
2723
|
-
const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
|
|
2724
|
-
if (missingWallets.length > 0) {
|
|
2725
|
-
throw new Error(
|
|
2726
|
-
`Cannot claim pregen wallets because wallet data is missing. Please call setUserShare first to load the wallet data for the following wallet IDs: ${missingWallets.map((w) => w.id).join(", ")}`
|
|
2727
|
-
);
|
|
2728
|
-
}
|
|
2729
|
-
let newRecoverySecret;
|
|
2730
|
-
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
2731
|
-
userId: this.userId,
|
|
2732
|
-
walletIds: pregenWallets.map((w) => w.id)
|
|
2733
|
-
});
|
|
2734
|
-
for (const walletId of walletIds) {
|
|
2735
|
-
const wallet = this.wallets[walletId];
|
|
2736
|
-
let refreshedShare;
|
|
2737
|
-
if (wallet.scheme === "ED25519") {
|
|
2738
|
-
const distributeRes = yield (0, import_shareDistribution.distributeNewShare)({
|
|
2739
|
-
ctx: this.ctx,
|
|
2740
|
-
userId: this.userId,
|
|
2741
|
-
walletId: wallet.id,
|
|
2742
|
-
userShare: this.wallets[wallet.id].signer,
|
|
2743
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2744
|
-
partnerId: wallet.partnerId,
|
|
2745
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2746
|
-
walletScheme: wallet.scheme
|
|
2747
|
-
});
|
|
2748
|
-
if (distributeRes.length > 0) {
|
|
2749
|
-
newRecoverySecret = distributeRes;
|
|
2750
|
-
}
|
|
2751
|
-
} else {
|
|
2752
|
-
refreshedShare = yield this.refreshShare({
|
|
2753
|
-
walletId: wallet.id,
|
|
2754
|
-
share: this.wallets[wallet.id].signer,
|
|
2755
|
-
oldPartnerId: wallet.partnerId,
|
|
2756
|
-
newPartnerId: wallet.partnerId,
|
|
2757
|
-
redistributeBackupEncryptedShares: true
|
|
2758
|
-
});
|
|
2759
|
-
if (refreshedShare.recoverySecret) {
|
|
2760
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
2763
|
-
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
2764
|
-
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
2765
|
-
userId: this.userId,
|
|
2766
|
-
pregenIdentifier: void 0,
|
|
2767
|
-
pregenIdentifierType: void 0
|
|
2768
|
-
});
|
|
2769
|
-
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
2770
|
-
delete walletNoSigner.signer;
|
|
2771
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
2772
|
-
wallet: walletNoSigner,
|
|
2773
|
-
recoverySecret: newRecoverySecret
|
|
2774
|
-
});
|
|
2775
|
-
}
|
|
2776
|
-
yield this.setWallets(this.wallets);
|
|
2777
|
-
return newRecoverySecret;
|
|
2031
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2032
|
+
return yield __privateGet(this, _pregenWalletService).claimPregenWallets(params);
|
|
2778
2033
|
});
|
|
2779
2034
|
}
|
|
2780
2035
|
/**
|
|
@@ -2784,24 +2039,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2784
2039
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
2785
2040
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
2786
2041
|
**/
|
|
2787
|
-
updatePregenWalletIdentifier(
|
|
2788
|
-
return __async(this,
|
|
2789
|
-
|
|
2790
|
-
newPregenId
|
|
2791
|
-
}) {
|
|
2792
|
-
this.requireApiKey();
|
|
2793
|
-
const [newPregenIdentifierType, newPregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(newPregenId);
|
|
2794
|
-
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2795
|
-
pregenIdentifier: newPregenIdentifier,
|
|
2796
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
2797
|
-
});
|
|
2798
|
-
if (!!this.wallets[walletId]) {
|
|
2799
|
-
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
2800
|
-
pregenIdentifier: newPregenIdentifier,
|
|
2801
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
2802
|
-
});
|
|
2803
|
-
yield this.setWallets(this.wallets);
|
|
2804
|
-
}
|
|
2042
|
+
updatePregenWalletIdentifier(params) {
|
|
2043
|
+
return __async(this, null, function* () {
|
|
2044
|
+
return yield __privateGet(this, _pregenWalletService).updatePregenWalletIdentifier(params);
|
|
2805
2045
|
});
|
|
2806
2046
|
}
|
|
2807
2047
|
/**
|
|
@@ -2811,18 +2051,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2811
2051
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
2812
2052
|
* @returns {boolean} whether the pregen wallet exists
|
|
2813
2053
|
**/
|
|
2814
|
-
hasPregenWallet(
|
|
2815
|
-
return __async(this,
|
|
2816
|
-
this.
|
|
2817
|
-
const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
|
|
2818
|
-
const wallets = yield this.getPregenWallets({ pregenId });
|
|
2819
|
-
const wallet = wallets.find(
|
|
2820
|
-
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
2821
|
-
);
|
|
2822
|
-
if (!wallet) {
|
|
2823
|
-
return false;
|
|
2824
|
-
}
|
|
2825
|
-
return true;
|
|
2054
|
+
hasPregenWallet(params) {
|
|
2055
|
+
return __async(this, null, function* () {
|
|
2056
|
+
return yield __privateGet(this, _pregenWalletService).hasPregenWallet(params);
|
|
2826
2057
|
});
|
|
2827
2058
|
}
|
|
2828
2059
|
/**
|
|
@@ -2833,64 +2064,21 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2833
2064
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2834
2065
|
**/
|
|
2835
2066
|
getPregenWallets() {
|
|
2836
|
-
return __async(this, arguments, function* (
|
|
2837
|
-
this.
|
|
2838
|
-
const res = yield this.ctx.client.getPregenWallets(
|
|
2839
|
-
pregenId ? (0, import_user_management_client.toPregenIds)(pregenId) : this.pregenIds,
|
|
2840
|
-
this.isPortal(),
|
|
2841
|
-
this.userId
|
|
2842
|
-
);
|
|
2843
|
-
return res.wallets.filter((w) => this.isWalletSupported((0, import_utils2.entityToWallet)(w)));
|
|
2067
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2068
|
+
return yield __privateGet(this, _pregenWalletService).getPregenWallets(params);
|
|
2844
2069
|
});
|
|
2845
2070
|
}
|
|
2846
2071
|
createGuestWallets() {
|
|
2847
2072
|
return __async(this, null, function* () {
|
|
2848
|
-
|
|
2849
|
-
if (__privateGet(this, _isCreateGuestWalletsPending)) {
|
|
2850
|
-
error = new Error("Guest wallets creation already in progress");
|
|
2851
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2852
|
-
throw error;
|
|
2853
|
-
}
|
|
2854
|
-
if (this.isGuestMode) {
|
|
2855
|
-
error = new Error("Guest wallets already created");
|
|
2856
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2857
|
-
throw error;
|
|
2858
|
-
}
|
|
2859
|
-
try {
|
|
2860
|
-
__privateSet(this, _isCreateGuestWalletsPending, true);
|
|
2861
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2862
|
-
const wallets = [];
|
|
2863
|
-
const guestId = (0, import_utils2.newUuid)();
|
|
2864
|
-
for (const type of yield this.getTypesToCreate(
|
|
2865
|
-
supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
|
|
2866
|
-
)) {
|
|
2867
|
-
const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenId: { guestId } });
|
|
2868
|
-
wallets.push(wallet);
|
|
2869
|
-
}
|
|
2870
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2871
|
-
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2872
|
-
return wallets;
|
|
2873
|
-
} catch (error2) {
|
|
2874
|
-
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.GUEST_WALLETS_CREATED, null, error2 == null ? void 0 : error2.message);
|
|
2875
|
-
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2876
|
-
throw error2;
|
|
2877
|
-
}
|
|
2073
|
+
return yield __privateGet(this, _pregenWalletService).createGuestWallets();
|
|
2878
2074
|
});
|
|
2879
2075
|
}
|
|
2880
|
-
encodeWalletBase64(wallet) {
|
|
2881
|
-
const walletJson = JSON.stringify(wallet);
|
|
2882
|
-
const base64Wallet = Buffer.from(walletJson).toString("base64");
|
|
2883
|
-
return base64Wallet;
|
|
2884
|
-
}
|
|
2885
2076
|
/**
|
|
2886
2077
|
* Encodes the current wallets encoded in Base 64.
|
|
2887
2078
|
* @returns {string} the encoded wallet string
|
|
2888
2079
|
**/
|
|
2889
2080
|
getUserShare() {
|
|
2890
|
-
|
|
2891
|
-
return null;
|
|
2892
|
-
}
|
|
2893
|
-
return Object.values(this.wallets).map((wallet) => this.encodeWalletBase64(wallet)).join("-");
|
|
2081
|
+
return __privateGet(this, _walletService).getUserShare();
|
|
2894
2082
|
}
|
|
2895
2083
|
/**
|
|
2896
2084
|
* Sets the current wallets from a Base 64 string.
|
|
@@ -2898,24 +2086,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2898
2086
|
**/
|
|
2899
2087
|
setUserShare(base64Wallets) {
|
|
2900
2088
|
return __async(this, null, function* () {
|
|
2901
|
-
|
|
2902
|
-
return;
|
|
2903
|
-
}
|
|
2904
|
-
const base64WalletsSplit = base64Wallets.split("-");
|
|
2905
|
-
for (const base64Wallet of base64WalletsSplit) {
|
|
2906
|
-
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
2907
|
-
const wallet = (0, import_utils2.migrateWallet)(JSON.parse(walletJson));
|
|
2908
|
-
this.wallets[wallet.id] = wallet;
|
|
2909
|
-
yield this.setWallets(this.wallets);
|
|
2910
|
-
}
|
|
2089
|
+
return yield __privateGet(this, _walletService).setUserShare(base64Wallets);
|
|
2911
2090
|
});
|
|
2912
2091
|
}
|
|
2913
2092
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2914
2093
|
return __async(this, null, function* () {
|
|
2094
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
2915
2095
|
return this.constructPortalUrl("txReview", {
|
|
2916
2096
|
pathId: transactionId,
|
|
2097
|
+
useLegacyUrl: authMethods.has(import_user_management_client.AuthMethod.PASSKEY),
|
|
2917
2098
|
params: {
|
|
2918
|
-
email: this.email,
|
|
2919
2099
|
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
2920
2100
|
}
|
|
2921
2101
|
});
|
|
@@ -2930,6 +2110,11 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2930
2110
|
});
|
|
2931
2111
|
});
|
|
2932
2112
|
}
|
|
2113
|
+
getWalletBalance(params) {
|
|
2114
|
+
return __async(this, null, function* () {
|
|
2115
|
+
return yield __privateGet(this, _walletService).getWalletBalance(params);
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2933
2118
|
/**
|
|
2934
2119
|
* Signs a message using one of the current wallets.
|
|
2935
2120
|
*
|
|
@@ -2952,7 +2137,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2952
2137
|
onPoll
|
|
2953
2138
|
}) {
|
|
2954
2139
|
var _a;
|
|
2955
|
-
this.assertIsValidWalletId(walletId);
|
|
2140
|
+
__privateGet(this, _walletService).assertIsValidWalletId(walletId);
|
|
2956
2141
|
const wallet = this.wallets[walletId];
|
|
2957
2142
|
let signerId = this.userId;
|
|
2958
2143
|
if (wallet.partnerId && !wallet.userId) {
|
|
@@ -3057,7 +2242,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3057
2242
|
onPoll
|
|
3058
2243
|
}) {
|
|
3059
2244
|
var _a;
|
|
3060
|
-
this.assertIsValidWalletId(walletId);
|
|
2245
|
+
__privateGet(this, _walletService).assertIsValidWalletId(walletId);
|
|
3061
2246
|
const wallet = this.wallets[walletId];
|
|
3062
2247
|
let signerId = this.userId;
|
|
3063
2248
|
if (wallet.partnerId && !wallet.userId) {
|
|
@@ -3163,12 +2348,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3163
2348
|
**/
|
|
3164
2349
|
keepSessionAlive() {
|
|
3165
2350
|
return __async(this, null, function* () {
|
|
3166
|
-
|
|
3167
|
-
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
3168
|
-
return true;
|
|
3169
|
-
} catch (e) {
|
|
3170
|
-
return false;
|
|
3171
|
-
}
|
|
2351
|
+
return yield __privateGet(this, _sessionManagementService).keepSessionAlive();
|
|
3172
2352
|
});
|
|
3173
2353
|
}
|
|
3174
2354
|
/**
|
|
@@ -3178,10 +2358,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3178
2358
|
*/
|
|
3179
2359
|
exportSession({ excludeSigners = false } = {}) {
|
|
3180
2360
|
const sessionInfo = {
|
|
3181
|
-
authInfo: __privateGet(this,
|
|
2361
|
+
authInfo: __privateGet(this, _authService).authInfo,
|
|
3182
2362
|
userId: this.userId,
|
|
3183
2363
|
wallets: structuredClone(this.wallets),
|
|
3184
|
-
currentWalletIds: this.currentWalletIds,
|
|
2364
|
+
currentWalletIds: __privateGet(this, _walletService).currentWalletIds,
|
|
3185
2365
|
sessionCookie: this.retrieveSessionCookie(),
|
|
3186
2366
|
externalWallets: this.externalWallets
|
|
3187
2367
|
};
|
|
@@ -3199,10 +2379,25 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3199
2379
|
importSession(serializedInstanceBase64) {
|
|
3200
2380
|
return __async(this, null, function* () {
|
|
3201
2381
|
var _a, _b;
|
|
2382
|
+
yield (0, import_stateListener.waitForAuthStateChange)({
|
|
2383
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2384
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => void 0 }],
|
|
2385
|
+
rejectPhases: [
|
|
2386
|
+
{
|
|
2387
|
+
phase: "authenticated",
|
|
2388
|
+
onPhase: () => new Error("Cannot import a session into a Para instance that already has an active session.")
|
|
2389
|
+
},
|
|
2390
|
+
{
|
|
2391
|
+
phase: "guest_mode",
|
|
2392
|
+
onPhase: () => new Error("Cannot import a session into a Para instance that is in guest mode.")
|
|
2393
|
+
}
|
|
2394
|
+
],
|
|
2395
|
+
waitForCoreAuthenticated: false
|
|
2396
|
+
});
|
|
3202
2397
|
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
3203
2398
|
const sessionInfo = (0, import_utils2.jsonParse)(serializedInstance);
|
|
3204
2399
|
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
3205
|
-
yield
|
|
2400
|
+
yield __privateGet(this, _authService).setAuthInfo(authInfo);
|
|
3206
2401
|
yield this.setUserId(sessionInfo.userId);
|
|
3207
2402
|
yield this.setWallets(sessionInfo.wallets);
|
|
3208
2403
|
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
@@ -3223,7 +2418,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3223
2418
|
}
|
|
3224
2419
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
3225
2420
|
}
|
|
2421
|
+
__privateGet(this, _sessionManagementService).isImportedSession = true;
|
|
2422
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_IMPORTED_SESSION, JSON.stringify(true));
|
|
3226
2423
|
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2424
|
+
__privateGet(this, _stateManager).send({ type: "SESSION_IMPORTED" });
|
|
3227
2425
|
});
|
|
3228
2426
|
}
|
|
3229
2427
|
/**
|
|
@@ -3232,22 +2430,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3232
2430
|
**/
|
|
3233
2431
|
getVerificationToken() {
|
|
3234
2432
|
return __async(this, null, function* () {
|
|
3235
|
-
|
|
3236
|
-
return sessionLookupId;
|
|
2433
|
+
return yield __privateGet(this, _sessionManagementService).getVerificationToken();
|
|
3237
2434
|
});
|
|
3238
2435
|
}
|
|
3239
2436
|
issueJwt() {
|
|
3240
|
-
return __async(this, arguments, function* (
|
|
3241
|
-
|
|
3242
|
-
return yield this.ctx.client.issueJwt({ keyIndex });
|
|
3243
|
-
} catch (error) {
|
|
3244
|
-
if (error.status === 403 || error.status === 401) {
|
|
3245
|
-
const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
|
|
3246
|
-
this.displayModalError(errorMessage);
|
|
3247
|
-
console.warn(errorMessage);
|
|
3248
|
-
}
|
|
3249
|
-
throw error;
|
|
3250
|
-
}
|
|
2437
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2438
|
+
return yield __privateGet(this, _sessionManagementService).issueJwt(params);
|
|
3251
2439
|
});
|
|
3252
2440
|
}
|
|
3253
2441
|
/**
|
|
@@ -3257,30 +2445,39 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3257
2445
|
**/
|
|
3258
2446
|
logout() {
|
|
3259
2447
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
yield this.
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
2448
|
+
yield __privateMethod(this, _ParaCore_instances, logout_fn).call(this, { clearPregenWallets });
|
|
2449
|
+
__privateGet(this, _pollingService).cancelAllPolling();
|
|
2450
|
+
yield __privateGet(this, _externalWalletService).disconnectAllExternalWallets();
|
|
2451
|
+
try {
|
|
2452
|
+
yield (0, import_stateListener.waitForAuthStateChange)({
|
|
2453
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2454
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => void 0 }],
|
|
2455
|
+
rejectInErrorPhaseOnly: true,
|
|
2456
|
+
timeoutMs: 5e3
|
|
3268
2457
|
});
|
|
3269
|
-
|
|
3270
|
-
} else {
|
|
3271
|
-
this.wallets = {};
|
|
2458
|
+
} catch (e) {
|
|
3272
2459
|
}
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Cancels any in-progress authentication flow, returning the auth state machine
|
|
2464
|
+
* to its initial unauthenticated state. Does not affect existing sessions or stored data.
|
|
2465
|
+
*
|
|
2466
|
+
* Resolves once the auth state machine has settled back to `unauthenticated`.
|
|
2467
|
+
*/
|
|
2468
|
+
cancelAuthFlow() {
|
|
2469
|
+
return __async(this, null, function* () {
|
|
2470
|
+
if (this.authPhase === "unauthenticated" || this.authPhase === "error") {
|
|
2471
|
+
return;
|
|
3283
2472
|
}
|
|
2473
|
+
const settled = (0, import_stateListener.waitForAuthStateChange)({
|
|
2474
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2475
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => true }],
|
|
2476
|
+
rejectInErrorPhaseOnly: true,
|
|
2477
|
+
timeoutMs: 5e3
|
|
2478
|
+
});
|
|
2479
|
+
__privateGet(this, _stateManager).send({ type: "CANCEL" });
|
|
2480
|
+
yield settled;
|
|
3284
2481
|
});
|
|
3285
2482
|
}
|
|
3286
2483
|
get toStringAdditions() {
|
|
@@ -3313,16 +2510,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3313
2510
|
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
3314
2511
|
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
3315
2512
|
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
3316
|
-
authInfo: __privateGet(this,
|
|
2513
|
+
authInfo: __privateGet(this, _authService).authInfo,
|
|
3317
2514
|
isGuestMode: this.isGuestMode,
|
|
3318
2515
|
userId: this.userId,
|
|
3319
2516
|
pregenIds: this.pregenIds,
|
|
3320
|
-
currentWalletIds: this.currentWalletIds,
|
|
3321
|
-
guestWalletIds: __privateGet(this,
|
|
2517
|
+
currentWalletIds: __privateGet(this, _walletService).currentWalletIds,
|
|
2518
|
+
guestWalletIds: __privateGet(this, _pregenWalletService).guestWalletIds,
|
|
3322
2519
|
wallets: redactedWallets,
|
|
3323
2520
|
externalWallets: redactedExternalWallets,
|
|
3324
2521
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3325
|
-
|
|
2522
|
+
isSetup: this.isSetup
|
|
3326
2523
|
}, this.toStringAdditions), {
|
|
3327
2524
|
ctx: {
|
|
3328
2525
|
apiKey: this.ctx.apiKey,
|
|
@@ -3338,90 +2535,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3338
2535
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3339
2536
|
}
|
|
3340
2537
|
devLog(...s) {
|
|
3341
|
-
if (this.ctx.env === import_types.Environment.DEV || this.ctx.env === import_types.Environment.SANDBOX) {
|
|
2538
|
+
if (this.ctx.env === import_types.Environment.DEV || this.ctx.env === import_types.Environment.SANDBOX || !!__privateGet(this, _debugLogsEnabled)) {
|
|
3342
2539
|
console.log(...s);
|
|
3343
2540
|
}
|
|
3344
2541
|
}
|
|
3345
2542
|
getNewCredentialAndUrl() {
|
|
3346
|
-
return __async(this, arguments, function* ({
|
|
3347
|
-
|
|
3348
|
-
isForNewDevice = false,
|
|
3349
|
-
portalTheme,
|
|
3350
|
-
shorten = false
|
|
3351
|
-
} = {}) {
|
|
3352
|
-
const userAuthMethods = yield this.supportedUserAuthMethods();
|
|
3353
|
-
const isEnclaveUser = userAuthMethods.has(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
3354
|
-
const isAddingBasicLogin = optsAuthMethod === "BASIC_LOGIN";
|
|
3355
|
-
if (isEnclaveUser && isAddingBasicLogin) {
|
|
3356
|
-
throw new Error("That user is already using basic login");
|
|
3357
|
-
}
|
|
3358
|
-
if (isEnclaveUser || isAddingBasicLogin) {
|
|
3359
|
-
isForNewDevice = true;
|
|
3360
|
-
}
|
|
3361
|
-
const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
|
|
3362
|
-
this.assertIsAuthSet();
|
|
3363
|
-
let passkeyId, passwordId, urlType, credentialId;
|
|
3364
|
-
if (!isAddingBasicLogin) {
|
|
3365
|
-
const canAddPasswordOrPIN = !userAuthMethods.has(import_user_management_client.AuthMethod.PASSWORD) && !userAuthMethods.has(import_user_management_client.AuthMethod.PIN);
|
|
3366
|
-
if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
|
|
3367
|
-
({
|
|
3368
|
-
data: { id: passkeyId }
|
|
3369
|
-
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
3370
|
-
status: import_user_management_client.AuthMethodStatus.PENDING,
|
|
3371
|
-
type: import_user_management_client.PublicKeyType.WEB
|
|
3372
|
-
}));
|
|
3373
|
-
urlType = "createAuth";
|
|
3374
|
-
}
|
|
3375
|
-
if (authMethods.includes("PASSWORD")) {
|
|
3376
|
-
if (!canAddPasswordOrPIN) {
|
|
3377
|
-
if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
|
|
3378
|
-
} else {
|
|
3379
|
-
({
|
|
3380
|
-
data: { id: passwordId }
|
|
3381
|
-
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3382
|
-
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3383
|
-
}));
|
|
3384
|
-
urlType = "createPassword";
|
|
3385
|
-
}
|
|
3386
|
-
}
|
|
3387
|
-
if (authMethods.includes("PIN")) {
|
|
3388
|
-
if (!canAddPasswordOrPIN) {
|
|
3389
|
-
if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
|
|
3390
|
-
} else {
|
|
3391
|
-
({
|
|
3392
|
-
data: { id: passwordId }
|
|
3393
|
-
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3394
|
-
status: import_user_management_client.AuthMethodStatus.PENDING
|
|
3395
|
-
}));
|
|
3396
|
-
urlType = "createPIN";
|
|
3397
|
-
}
|
|
3398
|
-
}
|
|
3399
|
-
credentialId = passkeyId != null ? passkeyId : passwordId;
|
|
3400
|
-
if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
|
|
3401
|
-
return { credentialId };
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
const { sessionId } = yield this.touchSession();
|
|
3405
|
-
const url = (isForNewDevice || urlType) && (yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
|
|
3406
|
-
isForNewDevice,
|
|
3407
|
-
pathId: credentialId,
|
|
3408
|
-
portalTheme,
|
|
3409
|
-
shorten,
|
|
3410
|
-
sessionId: isForNewDevice ? sessionId : void 0,
|
|
3411
|
-
addNewCredentialType: optsAuthMethod,
|
|
3412
|
-
addNewCredentialPasskeyId: passkeyId,
|
|
3413
|
-
addNewCredentialPasswordId: passwordId
|
|
3414
|
-
}));
|
|
3415
|
-
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
3416
|
-
});
|
|
3417
|
-
}
|
|
3418
|
-
addCredential(_0) {
|
|
3419
|
-
return __async(this, arguments, function* ({ authMethod }) {
|
|
3420
|
-
if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
|
|
3421
|
-
throw new Error("Passkeys are not supported.");
|
|
3422
|
-
}
|
|
3423
|
-
const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
|
|
3424
|
-
return url;
|
|
2543
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2544
|
+
return yield __privateGet(this, _authService).getNewCredentialAndUrl(params);
|
|
3425
2545
|
});
|
|
3426
2546
|
}
|
|
3427
2547
|
/**
|
|
@@ -3432,92 +2552,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3432
2552
|
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
3433
2553
|
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
3434
2554
|
*/
|
|
3435
|
-
getLoginUrl(
|
|
3436
|
-
return __async(this,
|
|
3437
|
-
|
|
3438
|
-
shorten = false,
|
|
3439
|
-
portalTheme,
|
|
3440
|
-
sessionId
|
|
3441
|
-
}) {
|
|
3442
|
-
if (!sessionId) {
|
|
3443
|
-
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
3444
|
-
}
|
|
3445
|
-
this.assertIsAuthSet();
|
|
3446
|
-
let urlType;
|
|
3447
|
-
switch (authMethod) {
|
|
3448
|
-
case "PASSKEY":
|
|
3449
|
-
urlType = "loginAuth";
|
|
3450
|
-
break;
|
|
3451
|
-
case "PASSWORD":
|
|
3452
|
-
urlType = "loginPassword";
|
|
3453
|
-
break;
|
|
3454
|
-
case "PIN":
|
|
3455
|
-
urlType = "loginPIN";
|
|
3456
|
-
break;
|
|
3457
|
-
case "BASIC_LOGIN":
|
|
3458
|
-
urlType = this.authInfo.authType === "externalWallet" ? "loginExternalWallet" : "loginOTP";
|
|
3459
|
-
break;
|
|
3460
|
-
default:
|
|
3461
|
-
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
3462
|
-
}
|
|
3463
|
-
return this.constructPortalUrl(urlType, {
|
|
3464
|
-
sessionId,
|
|
3465
|
-
shorten,
|
|
3466
|
-
portalTheme
|
|
3467
|
-
});
|
|
2555
|
+
getLoginUrl(params) {
|
|
2556
|
+
return __async(this, null, function* () {
|
|
2557
|
+
return yield __privateGet(this, _portalUrlService).getLoginUrl(params);
|
|
3468
2558
|
});
|
|
3469
2559
|
}
|
|
3470
2560
|
prepareLogin() {
|
|
3471
2561
|
return __async(this, null, function* () {
|
|
3472
|
-
|
|
3473
|
-
const { sessionLookupId } = yield this.touchSession(true);
|
|
3474
|
-
if (!this.loginEncryptionKeyPair) {
|
|
3475
|
-
yield this.setLoginEncryptionKeyPair();
|
|
3476
|
-
}
|
|
3477
|
-
return sessionLookupId;
|
|
2562
|
+
return __privateGet(this, _authService).prepareLogin();
|
|
3478
2563
|
});
|
|
3479
2564
|
}
|
|
3480
|
-
signUpOrLogIn(
|
|
2565
|
+
signUpOrLogIn(params) {
|
|
3481
2566
|
return __async(this, null, function* () {
|
|
3482
|
-
|
|
3483
|
-
let serverAuthState;
|
|
3484
|
-
try {
|
|
3485
|
-
serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3486
|
-
} catch (error) {
|
|
3487
|
-
if (error.message.includes("max beta users reached")) {
|
|
3488
|
-
this.displayModalError(
|
|
3489
|
-
`50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
|
|
3490
|
-
);
|
|
3491
|
-
}
|
|
3492
|
-
throw error;
|
|
3493
|
-
}
|
|
3494
|
-
const authInfo = serverAuthState.auth;
|
|
3495
|
-
if (this.fetchPregenWalletsOverride && (0, import_user_management_client.isPregenAuth)(authInfo)) {
|
|
3496
|
-
const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
|
|
3497
|
-
if (userShare) {
|
|
3498
|
-
yield this.setUserShare(userShare);
|
|
3499
|
-
}
|
|
3500
|
-
}
|
|
3501
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
|
|
2567
|
+
return yield __privateGet(this, _authService).signUpOrLogIn(params);
|
|
3502
2568
|
});
|
|
3503
2569
|
}
|
|
3504
|
-
|
|
2570
|
+
authenticateWithEmailOrPhone(params) {
|
|
3505
2571
|
return __async(this, null, function* () {
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
this
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
throw new Error("Account already exists.");
|
|
3518
|
-
}
|
|
3519
|
-
yield this.touchSession(true);
|
|
3520
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2572
|
+
return yield __privateGet(this, _authService).authenticateWithEmailOrPhone(params);
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
authenticateWithOAuth(params) {
|
|
2576
|
+
return __async(this, null, function* () {
|
|
2577
|
+
return yield __privateGet(this, _authService).authenticateWithOAuth(params);
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
verifyNewAccount(params) {
|
|
2581
|
+
return __async(this, null, function* () {
|
|
2582
|
+
return yield __privateGet(this, _authService).verifyNewAccount(params);
|
|
3521
2583
|
});
|
|
3522
2584
|
}
|
|
3523
2585
|
getLinkedAccounts() {
|
|
@@ -3603,10 +2665,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3603
2665
|
});
|
|
3604
2666
|
}
|
|
3605
2667
|
verifyLink() {
|
|
3606
|
-
return __async(this, arguments, function* (
|
|
3607
|
-
var
|
|
2668
|
+
return __async(this, arguments, function* (_e = {}) {
|
|
2669
|
+
var _f = _e, {
|
|
3608
2670
|
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3609
|
-
} =
|
|
2671
|
+
} = _f, opts = __objRest(_f, [
|
|
3610
2672
|
"accountLinkInProgress"
|
|
3611
2673
|
]);
|
|
3612
2674
|
try {
|
|
@@ -3673,8 +2735,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3673
2735
|
if (args.shouldOpenPopup) {
|
|
3674
2736
|
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: import_types.PopupType.EXPORT_PRIVATE_KEY });
|
|
3675
2737
|
}
|
|
2738
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
3676
2739
|
const exportPrivateKeyUrl = yield this.constructPortalUrl("exportPrivateKey", {
|
|
3677
|
-
pathId: walletId
|
|
2740
|
+
pathId: walletId,
|
|
2741
|
+
useLegacyUrl: authMethods.has(import_user_management_client.AuthMethod.PASSKEY)
|
|
3678
2742
|
});
|
|
3679
2743
|
if (args.shouldOpenPopup) {
|
|
3680
2744
|
this.popupWindow.location.href = exportPrivateKeyUrl;
|
|
@@ -3686,7 +2750,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3686
2750
|
});
|
|
3687
2751
|
}
|
|
3688
2752
|
};
|
|
3689
|
-
|
|
2753
|
+
_stateManager = new WeakMap();
|
|
2754
|
+
_authService = new WeakMap();
|
|
2755
|
+
_walletService = new WeakMap();
|
|
2756
|
+
_externalWalletService = new WeakMap();
|
|
2757
|
+
_pregenWalletService = new WeakMap();
|
|
2758
|
+
_pollingService = new WeakMap();
|
|
2759
|
+
_portalUrlService = new WeakMap();
|
|
2760
|
+
_sessionManagementService = new WeakMap();
|
|
2761
|
+
_debugLogsEnabled = new WeakMap();
|
|
3690
2762
|
_ParaCore_instances = new WeakSet();
|
|
3691
2763
|
assertPartner_fn = function() {
|
|
3692
2764
|
return __async(this, null, function* () {
|
|
@@ -3700,27 +2772,6 @@ assertPartner_fn = function() {
|
|
|
3700
2772
|
return this.partner;
|
|
3701
2773
|
});
|
|
3702
2774
|
};
|
|
3703
|
-
guestWalletIds_get = function() {
|
|
3704
|
-
var _a, _b, _c;
|
|
3705
|
-
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3706
|
-
return {};
|
|
3707
|
-
}
|
|
3708
|
-
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3709
|
-
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3710
|
-
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3711
|
-
return __spreadValues(__spreadValues({}, acc), (0, import_utils2.getEquivalentTypes)(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3712
|
-
var _a2;
|
|
3713
|
-
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3714
|
-
}, {}));
|
|
3715
|
-
}
|
|
3716
|
-
return acc;
|
|
3717
|
-
}, {}) : {};
|
|
3718
|
-
};
|
|
3719
|
-
guestWalletIdsArray_get = function() {
|
|
3720
|
-
return Object.entries(__privateGet(this, _ParaCore_instances, guestWalletIds_get)).reduce((acc, [type, ids]) => {
|
|
3721
|
-
return [...acc, ...ids.map((id) => [id, type])];
|
|
3722
|
-
}, []);
|
|
3723
|
-
};
|
|
3724
2775
|
toAuthInfo_fn = function({
|
|
3725
2776
|
email,
|
|
3726
2777
|
phone,
|
|
@@ -3752,27 +2803,6 @@ toAuthInfo_fn = function({
|
|
|
3752
2803
|
}
|
|
3753
2804
|
return (0, import_user_management_client.extractAuthInfo)(auth);
|
|
3754
2805
|
};
|
|
3755
|
-
setAuthInfo_fn = function(authInfo) {
|
|
3756
|
-
return __async(this, null, function* () {
|
|
3757
|
-
__privateSet(this, _authInfo, authInfo);
|
|
3758
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
3759
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_EMAIL);
|
|
3760
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_PHONE);
|
|
3761
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_COUNTRY_CODE);
|
|
3762
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
3763
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
3764
|
-
});
|
|
3765
|
-
};
|
|
3766
|
-
getPartner_fn = function(partnerId) {
|
|
3767
|
-
return __async(this, null, function* () {
|
|
3768
|
-
if (this.isPartnerOptional && !partnerId) {
|
|
3769
|
-
return void 0;
|
|
3770
|
-
}
|
|
3771
|
-
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3772
|
-
this.partner = res.data.partner;
|
|
3773
|
-
return this.partner;
|
|
3774
|
-
});
|
|
3775
|
-
};
|
|
3776
2806
|
assertIsLinkingAccount_fn = function(types) {
|
|
3777
2807
|
if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
|
|
3778
2808
|
throw new Error("no account linking in progress");
|
|
@@ -3792,49 +2822,6 @@ assertIsLinkingAccountOrStart_fn = function(type) {
|
|
|
3792
2822
|
return yield this.linkAccount({ type });
|
|
3793
2823
|
});
|
|
3794
2824
|
};
|
|
3795
|
-
getOAuthUrl_fn = function(_0) {
|
|
3796
|
-
return __async(this, arguments, function* ({
|
|
3797
|
-
method,
|
|
3798
|
-
appScheme,
|
|
3799
|
-
accountLinkInProgress,
|
|
3800
|
-
sessionLookupId,
|
|
3801
|
-
encryptionKey,
|
|
3802
|
-
portalCallbackParams
|
|
3803
|
-
}) {
|
|
3804
|
-
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3805
|
-
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
3806
|
-
}
|
|
3807
|
-
const [portalSessionLookupId, callback] = yield Promise.all([
|
|
3808
|
-
this.isPortal() ? this.touchSession(true).then((s) => s.sessionLookupId) : Promise.resolve(void 0),
|
|
3809
|
-
!accountLinkInProgress ? this.constructPortalUrl("oAuthCallback", __spreadValues({
|
|
3810
|
-
sessionId: sessionLookupId,
|
|
3811
|
-
oAuthMethod: method,
|
|
3812
|
-
appScheme,
|
|
3813
|
-
thisDevice: {
|
|
3814
|
-
sessionId: sessionLookupId,
|
|
3815
|
-
encryptionKey
|
|
3816
|
-
}
|
|
3817
|
-
}, this.isPortal() && {
|
|
3818
|
-
params: portalCallbackParams,
|
|
3819
|
-
// Build callback for legacy portal if needed
|
|
3820
|
-
useLegacyUrl: typeof window !== "undefined" ? window.location.host.includes("usecapsule") : false
|
|
3821
|
-
})) : Promise.resolve(false)
|
|
3822
|
-
]);
|
|
3823
|
-
return (0, import_utils2.constructUrl)({
|
|
3824
|
-
base: (0, import_userManagementClient.getBaseOAuthUrl)(this.ctx.env),
|
|
3825
|
-
path: `/auth/${method.toLowerCase()}`,
|
|
3826
|
-
params: __spreadValues(__spreadValues({
|
|
3827
|
-
apiKey: this.ctx.apiKey,
|
|
3828
|
-
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
3829
|
-
sessionLookupId,
|
|
3830
|
-
portalSessionLookupId,
|
|
3831
|
-
appScheme
|
|
3832
|
-
}, accountLinkInProgress ? {
|
|
3833
|
-
linkedAccountId: this.accountLinkInProgress.id
|
|
3834
|
-
} : {}), callback && { callback })
|
|
3835
|
-
});
|
|
3836
|
-
});
|
|
3837
|
-
};
|
|
3838
2825
|
waitForLoginProcess_fn = function() {
|
|
3839
2826
|
return __async(this, arguments, function* ({
|
|
3840
2827
|
isCanceled = () => false,
|
|
@@ -3862,7 +2849,7 @@ waitForLoginProcess_fn = function() {
|
|
|
3862
2849
|
var _a;
|
|
3863
2850
|
if (!this.isExternalWalletAuth && !isSwitchingWallets) {
|
|
3864
2851
|
this.devLog("[waitForLoginProcess] Clearing external wallets");
|
|
3865
|
-
this.externalWallets = {};
|
|
2852
|
+
__privateGet(this, _externalWalletService).externalWallets = {};
|
|
3866
2853
|
}
|
|
3867
2854
|
let pollCount = 0;
|
|
3868
2855
|
while (true) {
|
|
@@ -3907,7 +2894,7 @@ waitForLoginProcess_fn = function() {
|
|
|
3907
2894
|
continue;
|
|
3908
2895
|
}
|
|
3909
2896
|
this.devLog("[waitForLoginProcess] Authentication check passed, setting up user");
|
|
3910
|
-
session = yield this.userSetupAfterLogin();
|
|
2897
|
+
session = yield this.userSetupAfterLogin(session);
|
|
3911
2898
|
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3912
2899
|
this.devLog("[waitForLoginProcess] User setup complete", { needsWallet });
|
|
3913
2900
|
if (isSwitchingWallets) {
|
|
@@ -3932,7 +2919,9 @@ waitForLoginProcess_fn = function() {
|
|
|
3932
2919
|
}
|
|
3933
2920
|
}
|
|
3934
2921
|
this.devLog("[waitForLoginProcess] Getting transmission key shares");
|
|
3935
|
-
const tempSharesRes = yield this.getTransmissionKeyShares(
|
|
2922
|
+
const tempSharesRes = yield this.getTransmissionKeyShares({
|
|
2923
|
+
sessionLookupId: session.sessionLookupId
|
|
2924
|
+
});
|
|
3936
2925
|
this.devLog("[waitForLoginProcess] Transmission shares received", {
|
|
3937
2926
|
shareCount: tempSharesRes.data.temporaryShares.length,
|
|
3938
2927
|
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
@@ -3999,224 +2988,41 @@ waitForLoginProcess_fn = function() {
|
|
|
3999
2988
|
});
|
|
4000
2989
|
});
|
|
4001
2990
|
};
|
|
4002
|
-
|
|
4003
|
-
return __async(this,
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
this.
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
);
|
|
4011
|
-
const [pregenIdentifierType, pregenIdentifier] = (0, import_user_management_client.toPregenTypeAndId)(pregenId);
|
|
4012
|
-
let keygenRes;
|
|
4013
|
-
switch (walletType) {
|
|
4014
|
-
case "SOLANA":
|
|
4015
|
-
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
4016
|
-
this.ctx,
|
|
4017
|
-
pregenIdentifier,
|
|
4018
|
-
pregenIdentifierType,
|
|
4019
|
-
this.retrieveSessionCookie()
|
|
4020
|
-
);
|
|
4021
|
-
break;
|
|
4022
|
-
default:
|
|
4023
|
-
keygenRes = yield this.platformUtils.preKeygen(
|
|
4024
|
-
this.ctx,
|
|
4025
|
-
void 0,
|
|
4026
|
-
pregenIdentifier,
|
|
4027
|
-
pregenIdentifierType,
|
|
4028
|
-
walletType,
|
|
4029
|
-
null,
|
|
4030
|
-
this.retrieveSessionCookie()
|
|
4031
|
-
);
|
|
4032
|
-
break;
|
|
4033
|
-
}
|
|
4034
|
-
const { signer, walletId } = keygenRes;
|
|
4035
|
-
this.wallets[walletId] = {
|
|
4036
|
-
id: walletId,
|
|
4037
|
-
signer,
|
|
4038
|
-
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
4039
|
-
type: walletType,
|
|
4040
|
-
isPregen: true,
|
|
4041
|
-
pregenIdentifier,
|
|
4042
|
-
pregenIdentifierType
|
|
4043
|
-
};
|
|
4044
|
-
yield this.waitForPregenWalletAddress(walletId);
|
|
4045
|
-
yield this.populatePregenWalletAddresses();
|
|
4046
|
-
return this.wallets[walletId];
|
|
4047
|
-
});
|
|
4048
|
-
};
|
|
4049
|
-
_isCreateGuestWalletsPending = new WeakMap();
|
|
4050
|
-
prepareAuthState_fn = function(_0) {
|
|
4051
|
-
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
4052
|
-
var _a, _b;
|
|
4053
|
-
if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(import_user_management_client.AuthMethod.PIN))))) {
|
|
4054
|
-
opts.sessionLookupId = yield this.prepareLogin();
|
|
4055
|
-
}
|
|
4056
|
-
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
4057
|
-
const authInfo = __spreadValues(__spreadValues({}, (0, import_user_management_client.extractAuthInfo)(auth, { isRequired: true })), Object.fromEntries(
|
|
4058
|
-
Object.entries({
|
|
4059
|
-
displayName,
|
|
4060
|
-
pfpUrl,
|
|
4061
|
-
username,
|
|
4062
|
-
externalWallet
|
|
4063
|
-
}).filter(([_, v]) => !!v)
|
|
4064
|
-
));
|
|
4065
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
4066
|
-
yield this.assertIsAuthSet();
|
|
4067
|
-
if (!!externalWallet) {
|
|
4068
|
-
yield this.setExternalWallet([externalWallet]);
|
|
4069
|
-
}
|
|
4070
|
-
if (!!userId) {
|
|
4071
|
-
yield this.setUserId(userId);
|
|
2991
|
+
logout_fn = function() {
|
|
2992
|
+
return __async(this, arguments, function* ({
|
|
2993
|
+
clearPregenWallets = false,
|
|
2994
|
+
skipStateReset = false
|
|
2995
|
+
} = {}) {
|
|
2996
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2997
|
+
if (!isSessionActive && !skipStateReset) {
|
|
2998
|
+
__privateGet(this, _stateManager).send({ type: "LOGOUT" });
|
|
4072
2999
|
}
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
case "verify":
|
|
4080
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
|
|
4081
|
-
sessionLookupId: opts.sessionLookupId
|
|
4082
|
-
}));
|
|
4083
|
-
break;
|
|
4084
|
-
case "login":
|
|
4085
|
-
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4086
|
-
authState = serverAuthState;
|
|
4087
|
-
break;
|
|
4088
|
-
}
|
|
4089
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
4090
|
-
break;
|
|
4091
|
-
case "signup":
|
|
4092
|
-
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4093
|
-
authState = serverAuthState;
|
|
4094
|
-
break;
|
|
3000
|
+
yield this.ctx.client.logout();
|
|
3001
|
+
yield this.clearStorage();
|
|
3002
|
+
if (!clearPregenWallets) {
|
|
3003
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
3004
|
+
if (!wallet.pregenIdentifier) {
|
|
3005
|
+
delete this.wallets[id];
|
|
4095
3006
|
}
|
|
4096
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
4097
|
-
break;
|
|
4098
|
-
}
|
|
4099
|
-
return authState;
|
|
4100
|
-
});
|
|
4101
|
-
};
|
|
4102
|
-
prepareDoneState_fn = function(doneState) {
|
|
4103
|
-
return __async(this, null, function* () {
|
|
4104
|
-
let isSLOPossible = doneState.authMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
4105
|
-
this.isEnclaveUser = isSLOPossible;
|
|
4106
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_ENCLAVE_USER, JSON.stringify(isSLOPossible));
|
|
4107
|
-
return doneState;
|
|
4108
|
-
});
|
|
4109
|
-
};
|
|
4110
|
-
prepareVerificationState_fn = function(_0, _1) {
|
|
4111
|
-
return __async(this, arguments, function* (verifyState, {
|
|
4112
|
-
useShortUrls: shorten = false,
|
|
4113
|
-
portalTheme,
|
|
4114
|
-
sessionLookupId
|
|
4115
|
-
}) {
|
|
4116
|
-
var _a;
|
|
4117
|
-
let isSLOPossible = false;
|
|
4118
|
-
if (verifyState.nextStage === "login") {
|
|
4119
|
-
isSLOPossible = verifyState.loginAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
4120
|
-
} else if (verifyState.nextStage === "signup") {
|
|
4121
|
-
isSLOPossible = verifyState.signupAuthMethods.includes(import_user_management_client.AuthMethod.BASIC_LOGIN);
|
|
4122
|
-
}
|
|
4123
|
-
this.isEnclaveUser = isSLOPossible;
|
|
4124
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_ENCLAVE_USER, JSON.stringify(isSLOPossible));
|
|
4125
|
-
const isExternalWalletFullAuth = (_a = verifyState.externalWallet) == null ? void 0 : _a.withFullParaAuth;
|
|
4126
|
-
return __spreadValues(__spreadValues({}, verifyState), isSLOPossible || isExternalWalletFullAuth ? {
|
|
4127
|
-
loginUrl: yield this.getLoginUrl({
|
|
4128
|
-
authMethod: import_user_management_client.AuthMethod.BASIC_LOGIN,
|
|
4129
|
-
sessionId: sessionLookupId,
|
|
4130
|
-
shorten,
|
|
4131
|
-
portalTheme
|
|
4132
|
-
})
|
|
4133
|
-
} : {});
|
|
4134
|
-
});
|
|
4135
|
-
};
|
|
4136
|
-
prepareLoginState_fn = function(_0, _1) {
|
|
4137
|
-
return __async(this, arguments, function* (loginState, {
|
|
4138
|
-
useShortUrls: shorten = false,
|
|
4139
|
-
portalTheme,
|
|
4140
|
-
sessionLookupId
|
|
4141
|
-
}) {
|
|
4142
|
-
const _a = loginState, { loginAuthMethods = [], hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
4143
|
-
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(import_user_management_client.AuthMethod.PIN);
|
|
4144
|
-
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
4145
|
-
isPasskeySupported,
|
|
4146
|
-
loginAuthMethods
|
|
4147
|
-
}), isPasskeyPossible ? {
|
|
4148
|
-
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
4149
|
-
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
4150
|
-
sessionId: sessionLookupId,
|
|
4151
|
-
newDevice: {
|
|
4152
|
-
sessionId: sessionLookupId,
|
|
4153
|
-
encryptionKey: (0, import_utils.getPublicKeyHex)(this.loginEncryptionKeyPair)
|
|
4154
|
-
},
|
|
4155
|
-
shorten,
|
|
4156
|
-
portalTheme
|
|
4157
|
-
})
|
|
4158
|
-
} : {}), isPasswordPossible ? {
|
|
4159
|
-
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
4160
|
-
sessionId: sessionLookupId,
|
|
4161
|
-
shorten,
|
|
4162
|
-
portalTheme,
|
|
4163
|
-
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4164
|
-
})
|
|
4165
|
-
} : {}), isPINPossible ? {
|
|
4166
|
-
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
4167
|
-
sessionId: sessionLookupId,
|
|
4168
|
-
shorten,
|
|
4169
|
-
portalTheme,
|
|
4170
|
-
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4171
|
-
})
|
|
4172
|
-
} : {});
|
|
4173
|
-
});
|
|
4174
|
-
};
|
|
4175
|
-
prepareSignUpState_fn = function(_0, _1) {
|
|
4176
|
-
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
4177
|
-
const _a = serverSignupState, { signupAuthMethods = [] } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
4178
|
-
const isPasskeySupported = yield this.isPasskeySupported();
|
|
4179
|
-
const [isPasskey, isPassword, isPIN] = [
|
|
4180
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSKEY),
|
|
4181
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
4182
|
-
signupAuthMethods.includes(import_user_management_client.AuthMethod.PIN)
|
|
4183
|
-
];
|
|
4184
|
-
if (!isPasskey && !isPassword && !isPIN) {
|
|
4185
|
-
throw new Error(
|
|
4186
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
4187
|
-
);
|
|
4188
|
-
}
|
|
4189
|
-
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
4190
|
-
isPasskeySupported,
|
|
4191
|
-
signupAuthMethods
|
|
4192
|
-
});
|
|
4193
|
-
if (isPasskey) {
|
|
4194
|
-
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
4195
|
-
authMethod: "PASSKEY",
|
|
4196
|
-
shorten
|
|
4197
3007
|
});
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
if (isPassword) {
|
|
4202
|
-
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
4203
|
-
authMethod: "PASSWORD",
|
|
4204
|
-
portalTheme,
|
|
4205
|
-
shorten
|
|
4206
|
-
});
|
|
4207
|
-
signupState.passwordUrl = passwordUrl;
|
|
4208
|
-
signupState.passwordId = passwordId;
|
|
3008
|
+
yield this.setWallets(this.wallets);
|
|
3009
|
+
} else {
|
|
3010
|
+
__privateGet(this, _walletService).wallets = {};
|
|
4209
3011
|
}
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
3012
|
+
__privateGet(this, _walletService).currentWalletIds = {};
|
|
3013
|
+
__privateGet(this, _externalWalletService).externalWallets = {};
|
|
3014
|
+
this.loginEncryptionKeyPair = void 0;
|
|
3015
|
+
__privateGet(this, _authService).authInfo = void 0;
|
|
3016
|
+
this.accountLinkInProgress = void 0;
|
|
3017
|
+
__privateGet(this, _authService).userId = void 0;
|
|
3018
|
+
__privateGet(this, _sessionManagementService).sessionCookie = void 0;
|
|
3019
|
+
this.isEnclaveUser = false;
|
|
3020
|
+
if (isSessionActive) {
|
|
3021
|
+
(0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
|
|
3022
|
+
if (!skipStateReset) {
|
|
3023
|
+
__privateGet(this, _stateManager).send({ type: "LOGOUT" });
|
|
3024
|
+
}
|
|
4218
3025
|
}
|
|
4219
|
-
return signupState;
|
|
4220
3026
|
});
|
|
4221
3027
|
};
|
|
4222
3028
|
_ParaCore.version = constants.PARA_CORE_VERSION;
|