@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/esm/ParaCore.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
__spreadProps,
|
|
9
9
|
__spreadValues
|
|
10
10
|
} from "./chunk-7B52C2XE.js";
|
|
11
|
-
var
|
|
11
|
+
var _stateManager, _authService, _walletService, _externalWalletService, _pregenWalletService, _pollingService, _portalUrlService, _sessionManagementService, _debugLogsEnabled, _ParaCore_instances, assertPartner_fn, toAuthInfo_fn, assertIsLinkingAccount_fn, assertIsLinkingAccountOrStart_fn, waitForLoginProcess_fn, logout_fn;
|
|
12
12
|
import { Buffer as NodeBuffer } from "buffer";
|
|
13
13
|
if (typeof global !== "undefined") {
|
|
14
14
|
global.Buffer = global.Buffer || NodeBuffer;
|
|
@@ -21,85 +21,62 @@ if (typeof global !== "undefined") {
|
|
|
21
21
|
}
|
|
22
22
|
import {
|
|
23
23
|
AuthMethod,
|
|
24
|
-
AuthMethodStatus,
|
|
25
|
-
PublicKeyType,
|
|
26
24
|
extractAuthInfo,
|
|
27
|
-
isEmail,
|
|
28
|
-
isPhone,
|
|
29
|
-
isFarcaster,
|
|
30
|
-
isTelegram,
|
|
31
|
-
toPregenTypeAndId,
|
|
32
|
-
toPregenIds,
|
|
33
|
-
isExternalWallet,
|
|
34
25
|
WALLET_TYPES,
|
|
35
|
-
LINKED_ACCOUNT_TYPES
|
|
36
|
-
isPregenAuth
|
|
26
|
+
LINKED_ACCOUNT_TYPES
|
|
37
27
|
} from "@getpara/user-management-client";
|
|
38
28
|
import forge from "node-forge";
|
|
39
29
|
const { pki, jsbn } = forge;
|
|
40
|
-
import { decryptWithPrivateKey, getAsymmetricKeyPair
|
|
41
|
-
import {
|
|
30
|
+
import { decryptWithPrivateKey, getAsymmetricKeyPair } from "./cryptography/utils.js";
|
|
31
|
+
import { initClient } from "./external/userManagementClient.js";
|
|
42
32
|
import * as mpcComputationClient from "./external/mpcComputationClient.js";
|
|
43
|
-
import { distributeNewShare } from "./shares/shareDistribution.js";
|
|
44
33
|
import {
|
|
45
34
|
Environment,
|
|
46
35
|
PopupType,
|
|
47
36
|
ParaEvent,
|
|
48
37
|
AccountLinkError
|
|
49
38
|
} from "./types/index.js";
|
|
50
|
-
import { sendRecoveryForShare } from "./shares/recovery.js";
|
|
51
39
|
import {
|
|
52
40
|
autoBind,
|
|
53
41
|
formatPhoneNumber,
|
|
54
|
-
constructUrl,
|
|
55
42
|
dispatchEvent,
|
|
56
|
-
entityToWallet,
|
|
57
|
-
getCosmosAddress,
|
|
58
|
-
getEquivalentTypes,
|
|
59
43
|
getParaConnectBaseUrl,
|
|
60
|
-
getPortalBaseURL,
|
|
61
|
-
getSchemes,
|
|
62
|
-
isPregenIdentifierMatch,
|
|
63
|
-
isWalletSupported,
|
|
64
44
|
jsonParse,
|
|
65
45
|
migrateWallet,
|
|
66
|
-
newUuid,
|
|
67
46
|
setupListeners,
|
|
68
|
-
supportedWalletTypesEq,
|
|
69
|
-
truncateAddress,
|
|
70
47
|
WalletSchemeTypeMap,
|
|
71
|
-
shortenUrl,
|
|
72
|
-
isServerAuthState,
|
|
73
|
-
splitPhoneNumber,
|
|
74
|
-
currentWalletIdsEq,
|
|
75
48
|
isPortal
|
|
76
49
|
} from "./utils/index.js";
|
|
50
|
+
import { waitForAuthStateChange } from "./utils/stateListener.js";
|
|
77
51
|
import { TransactionReviewDenied, TransactionReviewTimeout } from "./errors.js";
|
|
78
52
|
import * as constants from "./constants.js";
|
|
79
53
|
import { EnclaveClient } from "./shares/enclave.js";
|
|
54
|
+
import { AuthService } from "./services/AuthService.js";
|
|
55
|
+
import { PollingService } from "./services/PollingService.js";
|
|
56
|
+
import { CoreStateManager } from "./state/CoreStateManager.js";
|
|
57
|
+
import { WalletService } from "./services/WalletService.js";
|
|
58
|
+
import { PregenWalletService } from "./services/PregenWalletService.js";
|
|
59
|
+
import { PortalUrlService } from "./services/PortalUrlService.js";
|
|
60
|
+
import { SessionManagementService } from "./services/SessionManagementService.js";
|
|
61
|
+
import { ExternalWalletService } from "./services/ExternalWalletService.js";
|
|
80
62
|
const _ParaCore = class _ParaCore {
|
|
81
63
|
constructor(envOrApiKey, apiKeyOrOpts, opts) {
|
|
82
64
|
__privateAdd(this, _ParaCore_instances);
|
|
65
|
+
__privateAdd(this, _stateManager);
|
|
66
|
+
__privateAdd(this, _authService);
|
|
67
|
+
__privateAdd(this, _walletService);
|
|
68
|
+
__privateAdd(this, _externalWalletService);
|
|
69
|
+
__privateAdd(this, _pregenWalletService);
|
|
70
|
+
__privateAdd(this, _pollingService);
|
|
71
|
+
__privateAdd(this, _portalUrlService);
|
|
72
|
+
__privateAdd(this, _sessionManagementService);
|
|
73
|
+
__privateAdd(this, _debugLogsEnabled);
|
|
83
74
|
this.popupWindow = null;
|
|
84
|
-
__privateAdd(this, _authInfo);
|
|
85
75
|
this.isSwitchingWallets = false;
|
|
86
76
|
this.isNativePasskey = false;
|
|
87
|
-
this.
|
|
77
|
+
this.isSetup = false;
|
|
88
78
|
this.accountLinkInProgress = void 0;
|
|
89
|
-
this.isEnclaveUser = false;
|
|
90
|
-
this.isAwaitingAccountCreation = false;
|
|
91
|
-
this.isAwaitingLogin = false;
|
|
92
|
-
this.isAwaitingFarcaster = false;
|
|
93
|
-
this.isAwaitingOAuth = false;
|
|
94
79
|
this.isWorkerInitialized = false;
|
|
95
|
-
/**
|
|
96
|
-
* 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.
|
|
97
|
-
*/
|
|
98
|
-
this.currentWalletIds = {};
|
|
99
|
-
/**
|
|
100
|
-
* Wallets associated with the `ParaCore` instance.
|
|
101
|
-
*/
|
|
102
|
-
this.externalWallets = {};
|
|
103
80
|
this.onRampPopup = void 0;
|
|
104
81
|
this.nonPersistedStorageKeys = [];
|
|
105
82
|
this.localStorageGetItem = (key) => {
|
|
@@ -133,7 +110,8 @@ const _ParaCore = class _ParaCore {
|
|
|
133
110
|
return this.platformUtils.sessionStorage.removeItem(key);
|
|
134
111
|
};
|
|
135
112
|
this.retrieveSessionCookie = () => {
|
|
136
|
-
|
|
113
|
+
var _a;
|
|
114
|
+
return (_a = __privateGet(this, _sessionManagementService)) == null ? void 0 : _a.sessionCookie;
|
|
137
115
|
};
|
|
138
116
|
this.retrieveEnclaveJwt = () => {
|
|
139
117
|
return this.enclaveJwt;
|
|
@@ -148,18 +126,21 @@ const _ParaCore = class _ParaCore {
|
|
|
148
126
|
this.clearStorage = (type = "all") => __async(this, null, function* () {
|
|
149
127
|
const isAll = type === "all";
|
|
150
128
|
if (isAll || type === "local") {
|
|
151
|
-
this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
152
|
-
this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
129
|
+
yield this.platformUtils.localStorage.clear(constants.PREFIX);
|
|
130
|
+
yield this.platformUtils.localStorage.clear(constants.PARA_PREFIX);
|
|
153
131
|
}
|
|
154
132
|
if (isAll || type === "session") {
|
|
155
|
-
this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
156
|
-
this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
133
|
+
yield this.platformUtils.sessionStorage.clear(constants.PREFIX);
|
|
134
|
+
yield this.platformUtils.sessionStorage.clear(constants.PARA_PREFIX);
|
|
157
135
|
}
|
|
158
136
|
if ((isAll || type === "secure") && this.platformUtils.secureStorage) {
|
|
159
|
-
this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
160
|
-
this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
137
|
+
yield this.platformUtils.secureStorage.clear(constants.PREFIX);
|
|
138
|
+
yield this.platformUtils.secureStorage.clear(constants.PARA_PREFIX);
|
|
161
139
|
}
|
|
162
140
|
});
|
|
141
|
+
this.initExternalWalletProvider = (params) => __async(this, null, function* () {
|
|
142
|
+
yield __privateGet(this, _externalWalletService).initExternalWalletProvider(params);
|
|
143
|
+
});
|
|
163
144
|
this.trackError = (methodName, err) => __async(this, null, function* () {
|
|
164
145
|
try {
|
|
165
146
|
yield this.ctx.client.trackError({
|
|
@@ -218,7 +199,7 @@ const _ParaCore = class _ParaCore {
|
|
|
218
199
|
};
|
|
219
200
|
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
220
201
|
}
|
|
221
|
-
|
|
202
|
+
__privateGet(this, _authService).authInfo = authInfo;
|
|
222
203
|
};
|
|
223
204
|
this.updateEnclaveJwtFromStorage = () => {
|
|
224
205
|
this.enclaveJwt = this.localStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_ENCLAVE_JWT) || void 0;
|
|
@@ -231,7 +212,7 @@ const _ParaCore = class _ParaCore {
|
|
|
231
212
|
}
|
|
232
213
|
};
|
|
233
214
|
this.updateUserIdFromStorage = () => {
|
|
234
|
-
this.userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
215
|
+
__privateGet(this, _authService).userId = this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID) || void 0;
|
|
235
216
|
};
|
|
236
217
|
this.updateWalletsFromStorage = () => __async(this, null, function* () {
|
|
237
218
|
var _a;
|
|
@@ -272,12 +253,13 @@ const _ParaCore = class _ParaCore {
|
|
|
272
253
|
}, {}) : fromJson;
|
|
273
254
|
})();
|
|
274
255
|
this.setCurrentWalletIds(currentWalletIds);
|
|
275
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
256
|
+
if (Object.values(this.wallets).filter((w) => __privateGet(this, _walletService).isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
276
257
|
this.findWalletId(void 0, { forbidPregen: true });
|
|
277
258
|
}
|
|
278
259
|
};
|
|
279
260
|
this.updateSessionCookieFromStorage = () => {
|
|
280
|
-
this.sessionCookie = this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || void 0;
|
|
261
|
+
__privateGet(this, _sessionManagementService).sessionCookie = this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE) || void 0;
|
|
262
|
+
__privateGet(this, _sessionManagementService).isImportedSession = this.localStorageGetItem(constants.LOCAL_STORAGE_IS_IMPORTED_SESSION) === "true" || false;
|
|
281
263
|
};
|
|
282
264
|
this.updateLoginEncryptionKeyPairFromStorage = () => {
|
|
283
265
|
const loginEncryptionKey = this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
@@ -300,6 +282,25 @@ const _ParaCore = class _ParaCore {
|
|
|
300
282
|
}
|
|
301
283
|
}
|
|
302
284
|
});
|
|
285
|
+
this.setCurrentWalletIds = (...params) => __async(this, null, function* () {
|
|
286
|
+
const [currentWalletIds, { needsWallet = false, sessionLookupId, newDeviceSessionLookupId } = {}] = params;
|
|
287
|
+
return yield __privateGet(this, _walletService).setCurrentWalletIds(currentWalletIds, {
|
|
288
|
+
needsWallet,
|
|
289
|
+
sessionLookupId,
|
|
290
|
+
newDeviceSessionLookupId
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
/**
|
|
294
|
+
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
295
|
+
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
296
|
+
* @param {string} [walletId] the wallet ID to validate.
|
|
297
|
+
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
298
|
+
* @returns {string} the wallet ID originally passed, or the one found.
|
|
299
|
+
*/
|
|
300
|
+
this.findWalletId = (...params) => {
|
|
301
|
+
const [walletId, filters = {}] = params;
|
|
302
|
+
return __privateGet(this, _walletService).findWalletId(walletId, filters);
|
|
303
|
+
};
|
|
303
304
|
/**
|
|
304
305
|
* Creates several new wallets with the desired types. If no types are provided, this method
|
|
305
306
|
* will create one for each of the non-optional types specified in the instance's `supportedWalletTypes`
|
|
@@ -309,12 +310,8 @@ const _ParaCore = class _ParaCore {
|
|
|
309
310
|
* @deprecated alias for `createWalletPerType`
|
|
310
311
|
**/
|
|
311
312
|
this.createWalletPerMissingType = this.createWalletPerType;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
walletId,
|
|
315
|
-
rpcUrl
|
|
316
|
-
}) {
|
|
317
|
-
return (yield this.ctx.client.getWalletBalance({ walletId, rpcUrl })).balance;
|
|
313
|
+
this.addCredential = (params) => __async(this, null, function* () {
|
|
314
|
+
return yield __privateGet(this, _authService).addCredential(params);
|
|
318
315
|
});
|
|
319
316
|
let env, apiKey;
|
|
320
317
|
const actualArgs = Array.from(arguments).filter((arg) => arg !== void 0);
|
|
@@ -345,6 +342,7 @@ const _ParaCore = class _ParaCore {
|
|
|
345
342
|
apiKey = apiKeyOrOpts;
|
|
346
343
|
}
|
|
347
344
|
if (!opts) opts = {};
|
|
345
|
+
__privateSet(this, _debugLogsEnabled, !!opts.enableDebugLogs);
|
|
348
346
|
let isE2E = false;
|
|
349
347
|
if (env === "E2E") {
|
|
350
348
|
isE2E = true;
|
|
@@ -379,7 +377,7 @@ const _ParaCore = class _ParaCore {
|
|
|
379
377
|
this.localStorageSetItem = this.sessionStorageSetItem;
|
|
380
378
|
}
|
|
381
379
|
this.persistSessionCookie = (cookie) => {
|
|
382
|
-
this.sessionCookie = cookie;
|
|
380
|
+
__privateGet(this, _sessionManagementService).sessionCookie = cookie;
|
|
383
381
|
(opts.useSessionStorage ? this.sessionStorageSetItem : this.localStorageSetItem)(
|
|
384
382
|
constants.LOCAL_STORAGE_SESSION_COOKIE,
|
|
385
383
|
cookie
|
|
@@ -434,6 +432,59 @@ const _ParaCore = class _ParaCore {
|
|
|
434
432
|
if (!this.platformUtils.isSyncStorage || opts.useStorageOverrides) {
|
|
435
433
|
return;
|
|
436
434
|
}
|
|
435
|
+
__privateSet(this, _authService, new AuthService(this));
|
|
436
|
+
__privateSet(this, _walletService, new WalletService(this));
|
|
437
|
+
__privateSet(this, _externalWalletService, new ExternalWalletService(this));
|
|
438
|
+
__privateSet(this, _pregenWalletService, new PregenWalletService(this));
|
|
439
|
+
__privateSet(this, _pollingService, new PollingService(this));
|
|
440
|
+
__privateSet(this, _portalUrlService, new PortalUrlService(this));
|
|
441
|
+
__privateSet(this, _sessionManagementService, new SessionManagementService(this));
|
|
442
|
+
__privateSet(this, _stateManager, new CoreStateManager(this));
|
|
443
|
+
__privateGet(this, _authService).init({
|
|
444
|
+
stateManager: __privateGet(this, _stateManager),
|
|
445
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
446
|
+
externalWalletService: __privateGet(this, _externalWalletService),
|
|
447
|
+
sessionManagementService: __privateGet(this, _sessionManagementService),
|
|
448
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
449
|
+
walletService: __privateGet(this, _walletService)
|
|
450
|
+
});
|
|
451
|
+
__privateGet(this, _walletService).init({
|
|
452
|
+
authService: __privateGet(this, _authService),
|
|
453
|
+
pollingService: __privateGet(this, _pollingService),
|
|
454
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
455
|
+
externalWalletService: __privateGet(this, _externalWalletService)
|
|
456
|
+
});
|
|
457
|
+
__privateGet(this, _externalWalletService).init({
|
|
458
|
+
stateManager: __privateGet(this, _stateManager),
|
|
459
|
+
authService: __privateGet(this, _authService),
|
|
460
|
+
walletService: __privateGet(this, _walletService)
|
|
461
|
+
});
|
|
462
|
+
__privateGet(this, _pollingService).init({
|
|
463
|
+
authService: __privateGet(this, _authService),
|
|
464
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
465
|
+
walletService: __privateGet(this, _walletService),
|
|
466
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
467
|
+
sessionManagementService: __privateGet(this, _sessionManagementService)
|
|
468
|
+
});
|
|
469
|
+
__privateGet(this, _pregenWalletService).init({
|
|
470
|
+
stateManager: __privateGet(this, _stateManager),
|
|
471
|
+
authService: __privateGet(this, _authService),
|
|
472
|
+
walletService: __privateGet(this, _walletService),
|
|
473
|
+
pollingService: __privateGet(this, _pollingService)
|
|
474
|
+
});
|
|
475
|
+
__privateGet(this, _portalUrlService).init({
|
|
476
|
+
authService: __privateGet(this, _authService),
|
|
477
|
+
walletService: __privateGet(this, _walletService),
|
|
478
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
479
|
+
sessionManagementService: __privateGet(this, _sessionManagementService)
|
|
480
|
+
});
|
|
481
|
+
__privateGet(this, _sessionManagementService).init({
|
|
482
|
+
authService: __privateGet(this, _authService),
|
|
483
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
484
|
+
walletService: __privateGet(this, _walletService),
|
|
485
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
486
|
+
externalWalletService: __privateGet(this, _externalWalletService)
|
|
487
|
+
});
|
|
437
488
|
this.initializeFromStorage();
|
|
438
489
|
setupListeners.bind(this)();
|
|
439
490
|
autoBind(this);
|
|
@@ -453,71 +504,183 @@ const _ParaCore = class _ParaCore {
|
|
|
453
504
|
"signTransaction"
|
|
454
505
|
]);
|
|
455
506
|
}
|
|
507
|
+
__privateGet(this, _stateManager).start();
|
|
456
508
|
}
|
|
457
509
|
setModalError(_error) {
|
|
458
510
|
return;
|
|
459
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* The current readiness state.
|
|
514
|
+
*/
|
|
515
|
+
get isReady() {
|
|
516
|
+
return __privateGet(this, _stateManager).getSnapshot().isReady;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* The current phase of the core flow.
|
|
520
|
+
*/
|
|
521
|
+
get corePhase() {
|
|
522
|
+
return __privateGet(this, _stateManager).getSnapshot().phase;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* The current phase of the authentication flow.
|
|
526
|
+
*/
|
|
527
|
+
get authPhase() {
|
|
528
|
+
return __privateGet(this, _stateManager).getSnapshot().authStatePhase;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* The current phase of the wallet flow.
|
|
532
|
+
*/
|
|
533
|
+
get walletPhase() {
|
|
534
|
+
return __privateGet(this, _stateManager).getSnapshot().walletStatePhase;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Any error that has occurred in the core flow.
|
|
538
|
+
*/
|
|
539
|
+
get error() {
|
|
540
|
+
return __privateGet(this, _stateManager).getSnapshot().error;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Get the current state of the core, auth, and wallet phases.
|
|
544
|
+
* @returns An object containing the current core, auth, and wallet state phases, along with any error.
|
|
545
|
+
*/
|
|
546
|
+
getCurrentState() {
|
|
547
|
+
const state = __privateGet(this, _stateManager).getSnapshot();
|
|
548
|
+
return {
|
|
549
|
+
corePhase: state.phase,
|
|
550
|
+
authPhase: state.authStatePhase,
|
|
551
|
+
walletPhase: state.walletStatePhase,
|
|
552
|
+
authStateInfo: state.authStateInfo,
|
|
553
|
+
error: state.error,
|
|
554
|
+
isReady: state.isReady
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Subscribe to changes in the core, auth, and wallet state phases.
|
|
559
|
+
*
|
|
560
|
+
* This method immediately calls the callback with the current state, then continues
|
|
561
|
+
* to call it whenever any phase changes. This ensures you never miss the initial state
|
|
562
|
+
* and can react to all subsequent changes.
|
|
563
|
+
*
|
|
564
|
+
* @param callback A function that will be called with the current state phases whenever they change.
|
|
565
|
+
* The callback receives an object containing `corePhase`, `authPhase`, `walletPhase`, and `error`.
|
|
566
|
+
*
|
|
567
|
+
* @returns A function that can be called to unsubscribe from the state changes.
|
|
568
|
+
* Always call this function when your component unmounts or when you no longer need updates
|
|
569
|
+
* to prevent memory leaks.
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* ```typescript
|
|
573
|
+
* // React example
|
|
574
|
+
* useEffect(() => {
|
|
575
|
+
* const unsubscribe = paraClient.onStatePhaseChange((snapshot) => {
|
|
576
|
+
* console.log('Core phase:', snapshot.corePhase);
|
|
577
|
+
* console.log('Auth phase:', snapshot.authPhase);
|
|
578
|
+
* console.log('Wallet phase:', snapshot.walletPhase);
|
|
579
|
+
*
|
|
580
|
+
* if (snapshot.error) {
|
|
581
|
+
* console.error('Para error:', snapshot.error.message);
|
|
582
|
+
* }
|
|
583
|
+
* });
|
|
584
|
+
*
|
|
585
|
+
* return unsubscribe; // Cleanup on unmount
|
|
586
|
+
* }, [paraClient]);
|
|
587
|
+
*
|
|
588
|
+
* // Vue example
|
|
589
|
+
* onMounted(() => {
|
|
590
|
+
* const unsubscribe = paraClient.onStatePhaseChange((state) => {
|
|
591
|
+
* phases.value = state;
|
|
592
|
+
* });
|
|
593
|
+
*
|
|
594
|
+
* onUnmounted(unsubscribe);
|
|
595
|
+
* });
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
onStatePhaseChange(callback) {
|
|
599
|
+
let lastSnapshot = null;
|
|
600
|
+
const fullListener = (state) => {
|
|
601
|
+
const currentSnapshot = {
|
|
602
|
+
corePhase: state.phase,
|
|
603
|
+
authPhase: state.authStatePhase,
|
|
604
|
+
walletPhase: state.walletStatePhase,
|
|
605
|
+
authStateInfo: state.authStateInfo,
|
|
606
|
+
error: state.error,
|
|
607
|
+
isReady: state.isReady
|
|
608
|
+
};
|
|
609
|
+
if (!lastSnapshot || lastSnapshot.corePhase !== currentSnapshot.corePhase || lastSnapshot.authPhase !== currentSnapshot.authPhase || lastSnapshot.walletPhase !== currentSnapshot.walletPhase || lastSnapshot.error !== currentSnapshot.error || lastSnapshot.isReady !== currentSnapshot.isReady) {
|
|
610
|
+
lastSnapshot = currentSnapshot;
|
|
611
|
+
callback(currentSnapshot);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
return __privateGet(this, _stateManager).onStateChange(fullListener);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Subscribe to changes in the readiness state of the ParaCore instance.
|
|
618
|
+
* @param callback A function that will be called with the new readiness state.
|
|
619
|
+
* @returns A function that can be called to unsubscribe from the readiness state changes.
|
|
620
|
+
*/
|
|
621
|
+
onReadyStateChange(callback) {
|
|
622
|
+
let lastIsReady = null;
|
|
623
|
+
const unsubscribe = __privateGet(this, _stateManager).onStateChange((state) => {
|
|
624
|
+
if (lastIsReady !== state.isReady) {
|
|
625
|
+
lastIsReady = state.isReady;
|
|
626
|
+
callback(state.isReady);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return () => unsubscribe();
|
|
630
|
+
}
|
|
460
631
|
get authInfo() {
|
|
461
|
-
|
|
632
|
+
var _a;
|
|
633
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.authInfo;
|
|
462
634
|
}
|
|
463
635
|
get email() {
|
|
464
636
|
var _a;
|
|
465
|
-
return
|
|
637
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.email;
|
|
466
638
|
}
|
|
467
639
|
get phone() {
|
|
468
640
|
var _a;
|
|
469
|
-
return
|
|
641
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.phone;
|
|
470
642
|
}
|
|
471
643
|
get farcasterUsername() {
|
|
472
644
|
var _a;
|
|
473
|
-
return
|
|
645
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.farcasterUsername;
|
|
474
646
|
}
|
|
475
647
|
get telegramUserId() {
|
|
476
648
|
var _a;
|
|
477
|
-
return
|
|
649
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.telegramUserId;
|
|
478
650
|
}
|
|
479
651
|
get externalWalletWithParaAuth() {
|
|
480
|
-
|
|
481
|
-
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
652
|
+
return __privateGet(this, _externalWalletService).externalWalletWithParaAuth;
|
|
482
653
|
}
|
|
483
654
|
get externalWalletConnectionType() {
|
|
484
|
-
|
|
485
|
-
return "AUTHENTICATED";
|
|
486
|
-
} else if (this.isExternalWalletWithVerification) {
|
|
487
|
-
return "VERIFICATION";
|
|
488
|
-
} else if (!!Object.keys(this.externalWallets).length) {
|
|
489
|
-
const hasEmbeddedWallets = Object.keys(this.wallets).some((id) => !this.wallets[id].isExternal);
|
|
490
|
-
if (hasEmbeddedWallets) {
|
|
491
|
-
return "NONE";
|
|
492
|
-
} else {
|
|
493
|
-
return "CONNECTION_ONLY";
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
return "NONE";
|
|
655
|
+
return __privateGet(this, _externalWalletService).externalWalletConnectionType;
|
|
497
656
|
}
|
|
498
|
-
get
|
|
657
|
+
get userId() {
|
|
499
658
|
var _a;
|
|
500
|
-
return
|
|
659
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.userId;
|
|
660
|
+
}
|
|
661
|
+
get isEnclaveUser() {
|
|
662
|
+
return __privateGet(this, _authService).isEnclaveUser;
|
|
663
|
+
}
|
|
664
|
+
set isEnclaveUser(value) {
|
|
665
|
+
__privateGet(this, _authService).isEnclaveUser = value;
|
|
666
|
+
}
|
|
667
|
+
get isEmail() {
|
|
668
|
+
return __privateGet(this, _authService).isEmail;
|
|
501
669
|
}
|
|
502
670
|
get isPhone() {
|
|
503
|
-
|
|
504
|
-
return isPhone((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
671
|
+
return __privateGet(this, _authService).isPhone;
|
|
505
672
|
}
|
|
506
673
|
get isFarcaster() {
|
|
507
|
-
|
|
508
|
-
return isFarcaster((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
674
|
+
return __privateGet(this, _authService).isFarcaster;
|
|
509
675
|
}
|
|
510
676
|
get isTelegram() {
|
|
511
|
-
|
|
512
|
-
return isTelegram((_a = this.authInfo) == null ? void 0 : _a.auth);
|
|
677
|
+
return __privateGet(this, _authService).isTelegram;
|
|
513
678
|
}
|
|
514
679
|
get isExternalWalletAuth() {
|
|
515
|
-
|
|
516
|
-
return 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);
|
|
680
|
+
return __privateGet(this, _authService).isExternalWalletAuth;
|
|
517
681
|
}
|
|
518
682
|
get isExternalWalletWithVerification() {
|
|
519
|
-
|
|
520
|
-
return 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);
|
|
683
|
+
return __privateGet(this, _authService).isExternalWalletWithVerification;
|
|
521
684
|
}
|
|
522
685
|
get partnerId() {
|
|
523
686
|
var _a;
|
|
@@ -531,45 +694,42 @@ const _ParaCore = class _ParaCore {
|
|
|
531
694
|
var _a;
|
|
532
695
|
return (_a = this.partner) == null ? void 0 : _a.logoUrl;
|
|
533
696
|
}
|
|
697
|
+
get currentWalletIds() {
|
|
698
|
+
return __privateGet(this, _walletService).currentWalletIds;
|
|
699
|
+
}
|
|
534
700
|
get currentWalletIdsArray() {
|
|
535
|
-
|
|
536
|
-
return ((_b = (_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) != null ? _b : Object.keys(this.currentWalletIds).map((type) => ({ type }))).reduce(
|
|
537
|
-
(acc, { type }) => {
|
|
538
|
-
var _a2;
|
|
539
|
-
return [
|
|
540
|
-
...acc,
|
|
541
|
-
...((_a2 = this.currentWalletIds[type]) != null ? _a2 : []).map((id) => {
|
|
542
|
-
return [id, type];
|
|
543
|
-
})
|
|
544
|
-
];
|
|
545
|
-
},
|
|
546
|
-
[]
|
|
547
|
-
);
|
|
701
|
+
return __privateGet(this, _walletService).currentWalletIdsArray;
|
|
548
702
|
}
|
|
549
703
|
get currentWalletIdsUnique() {
|
|
550
|
-
return
|
|
704
|
+
return __privateGet(this, _walletService).currentWalletIdsUnique;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Wallets associated with the `ParaCore` instance. Retrieve a particular wallet using `para.wallets[walletId]`.
|
|
708
|
+
*/
|
|
709
|
+
get wallets() {
|
|
710
|
+
var _a;
|
|
711
|
+
return (_a = __privateGet(this, _walletService)) == null ? void 0 : _a.wallets;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Wallets associated with the `ParaCore` instance.
|
|
715
|
+
*/
|
|
716
|
+
get externalWallets() {
|
|
717
|
+
var _a;
|
|
718
|
+
return (_a = __privateGet(this, _externalWalletService)) == null ? void 0 : _a.externalWallets;
|
|
551
719
|
}
|
|
552
720
|
/**
|
|
553
721
|
* A map of pre-generated wallet identifiers that can be claimed in the current instance.
|
|
554
722
|
*/
|
|
555
723
|
get pregenIds() {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (((_a = acc[wallet.pregenIdentifierType]) != null ? _a : []).includes(wallet.pregenIdentifier)) {
|
|
559
|
-
return acc;
|
|
560
|
-
}
|
|
561
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
562
|
-
[wallet.pregenIdentifierType]: [
|
|
563
|
-
.../* @__PURE__ */ new Set([...(_b = acc[wallet.pregenIdentifierType]) != null ? _b : [], wallet.pregenIdentifier])
|
|
564
|
-
]
|
|
565
|
-
});
|
|
566
|
-
}, {}));
|
|
724
|
+
var _a;
|
|
725
|
+
return (_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.pregenIds;
|
|
567
726
|
}
|
|
568
727
|
/**
|
|
569
728
|
* Whether the instance has multiple wallets connected.
|
|
570
729
|
*/
|
|
571
730
|
get isMultiWallet() {
|
|
572
|
-
|
|
731
|
+
var _a;
|
|
732
|
+
return this.currentWalletIdsArray.length > 1 || ((_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.guestWalletIdsArray.length) > 1;
|
|
573
733
|
}
|
|
574
734
|
get isNoWalletConfig() {
|
|
575
735
|
var _a;
|
|
@@ -634,60 +794,6 @@ const _ParaCore = class _ParaCore {
|
|
|
634
794
|
);
|
|
635
795
|
}
|
|
636
796
|
}
|
|
637
|
-
isWalletSupported(wallet) {
|
|
638
|
-
var _a, _b;
|
|
639
|
-
return !((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes) || isWalletSupported((_b = this.partner.supportedWalletTypes.map(({ type }) => type)) != null ? _b : [], wallet);
|
|
640
|
-
}
|
|
641
|
-
isWalletOwned(wallet) {
|
|
642
|
-
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;
|
|
643
|
-
}
|
|
644
|
-
isPregenWalletUnclaimed(wallet) {
|
|
645
|
-
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));
|
|
646
|
-
}
|
|
647
|
-
isPregenWalletClaimable(wallet) {
|
|
648
|
-
return this.isWalletSupported(wallet) && this.isPregenWalletUnclaimed(wallet) && (!["EMAIL", "PHONE", "TELEGRAM"].includes(wallet == null ? void 0 : wallet.pregenIdentifierType) || isPregenIdentifierMatch(
|
|
649
|
-
(wallet == null ? void 0 : wallet.pregenIdentifierType) === "EMAIL" ? this.email : (wallet == null ? void 0 : wallet.pregenIdentifierType) === "TELEGRAM" ? this.telegramUserId : this.getPhoneNumber(),
|
|
650
|
-
wallet == null ? void 0 : wallet.pregenIdentifier,
|
|
651
|
-
wallet == null ? void 0 : wallet.pregenIdentifierType
|
|
652
|
-
));
|
|
653
|
-
}
|
|
654
|
-
isWalletUsable(walletId, { type: types, scheme: schemes, forbidPregen = false } = {}, throwError = false) {
|
|
655
|
-
var _a, _b;
|
|
656
|
-
let error;
|
|
657
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[walletId]) {
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
if (!this.wallets[walletId]) {
|
|
661
|
-
error = `wallet with id ${walletId} does not exist`;
|
|
662
|
-
} else {
|
|
663
|
-
const wallet = this.wallets[walletId];
|
|
664
|
-
const [isUnclaimed, isOwned] = [this.isPregenWalletUnclaimed(wallet), this.isWalletOwned(wallet)];
|
|
665
|
-
if (forbidPregen && isUnclaimed && wallet.pregenIdentifierType !== "GUEST_ID") {
|
|
666
|
-
error = `pre-generated wallet with id ${wallet == null ? void 0 : wallet.id} cannot be selected`;
|
|
667
|
-
} else if (!isOwned && !isUnclaimed) {
|
|
668
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} is not owned by the current user`;
|
|
669
|
-
} else if (!this.isWalletSupported(wallet)) {
|
|
670
|
-
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(", ")}`;
|
|
671
|
-
} else if (types && (!getEquivalentTypes(types).includes(wallet == null ? void 0 : wallet.type) || isOwned && !types.some((type) => {
|
|
672
|
-
var _a2, _b2;
|
|
673
|
-
return (_b2 = (_a2 = this.currentWalletIds) == null ? void 0 : _a2[type]) == null ? void 0 : _b2.includes(walletId);
|
|
674
|
-
}))) {
|
|
675
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and type ${wallet == null ? void 0 : wallet.type} cannot be selected`;
|
|
676
|
-
} else if (schemes && !schemes.includes(wallet == null ? void 0 : wallet.scheme)) {
|
|
677
|
-
error = `wallet with id ${wallet == null ? void 0 : wallet.id} and scheme ${wallet == null ? void 0 : wallet.scheme} cannot be selected`;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
if (error) {
|
|
681
|
-
if (throwError) {
|
|
682
|
-
throw new Error(error);
|
|
683
|
-
}
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
return true;
|
|
687
|
-
}
|
|
688
|
-
truncateAddress(...args) {
|
|
689
|
-
return truncateAddress(args[0], args[1], __spreadValues({ prefix: this.cosmosPrefix }, args[2] || {}));
|
|
690
|
-
}
|
|
691
797
|
/**
|
|
692
798
|
* Returns the formatted address for the desired wallet ID, depending on your app settings.
|
|
693
799
|
* @param {string} walletId the ID of the wallet address to display.
|
|
@@ -696,32 +802,9 @@ const _ParaCore = class _ParaCore {
|
|
|
696
802
|
* @param {TWalletType} options.addressType the type of address to display.
|
|
697
803
|
* @returns the formatted address
|
|
698
804
|
*/
|
|
699
|
-
getDisplayAddress(
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
const wallet2 = this.externalWallets[walletId];
|
|
703
|
-
return options.truncate ? truncateAddress(wallet2.address, wallet2.type, {
|
|
704
|
-
prefix: (_a = this.partner) == null ? void 0 : _a.cosmosPrefix,
|
|
705
|
-
targetLength: options.targetLength
|
|
706
|
-
}) : wallet2.address;
|
|
707
|
-
}
|
|
708
|
-
const wallet = this.findWallet(walletId, options.addressType);
|
|
709
|
-
if (!wallet) {
|
|
710
|
-
return void 0;
|
|
711
|
-
}
|
|
712
|
-
let str;
|
|
713
|
-
let prefix;
|
|
714
|
-
switch (wallet.type) {
|
|
715
|
-
case "COSMOS":
|
|
716
|
-
prefix = (_d = (_c = options.cosmosPrefix) != null ? _c : (_b = this.partner) == null ? void 0 : _b.cosmosPrefix) != null ? _d : "cosmos";
|
|
717
|
-
str = getCosmosAddress(wallet.publicKey, prefix);
|
|
718
|
-
break;
|
|
719
|
-
default:
|
|
720
|
-
prefix = this.cosmosPrefix;
|
|
721
|
-
str = wallet.address;
|
|
722
|
-
break;
|
|
723
|
-
}
|
|
724
|
-
return options.truncate ? truncateAddress(str, wallet.type, { prefix, targetLength: options.targetLength }) : str;
|
|
805
|
+
getDisplayAddress(...params) {
|
|
806
|
+
const [walletId, options = {}] = params;
|
|
807
|
+
return __privateGet(this, _walletService).getDisplayAddress(walletId, options);
|
|
725
808
|
}
|
|
726
809
|
/**
|
|
727
810
|
* Returns a unique hash for a wallet suitable for use as an identicon seed.
|
|
@@ -729,13 +812,8 @@ const _ParaCore = class _ParaCore {
|
|
|
729
812
|
* @param {boolean} options.addressType used to format the hash for another wallet type.
|
|
730
813
|
* @returns the identicon hash string
|
|
731
814
|
*/
|
|
732
|
-
getIdenticonHash(
|
|
733
|
-
|
|
734
|
-
const wallet2 = this.externalWallets[walletId];
|
|
735
|
-
return `${wallet2.id}-${wallet2.address}-${wallet2.type}`;
|
|
736
|
-
}
|
|
737
|
-
const wallet = this.findWallet(walletId, overrideType);
|
|
738
|
-
return wallet ? `${wallet.id}-${wallet.address}-${wallet.type}` : void 0;
|
|
815
|
+
getIdenticonHash(...params) {
|
|
816
|
+
return __privateGet(this, _walletService).getIdenticonHash(...params);
|
|
739
817
|
}
|
|
740
818
|
getWallets() {
|
|
741
819
|
return this.wallets;
|
|
@@ -746,189 +824,7 @@ const _ParaCore = class _ParaCore {
|
|
|
746
824
|
}
|
|
747
825
|
constructPortalUrl(_0) {
|
|
748
826
|
return __async(this, arguments, function* (type, opts = {}) {
|
|
749
|
-
|
|
750
|
-
const [
|
|
751
|
-
isCreate,
|
|
752
|
-
isLogin,
|
|
753
|
-
isOnRamp,
|
|
754
|
-
isOAuth,
|
|
755
|
-
isOAuthCallback,
|
|
756
|
-
isTelegramLogin,
|
|
757
|
-
isFarcasterLogin,
|
|
758
|
-
isAddNewCredential,
|
|
759
|
-
isSwitchWallets,
|
|
760
|
-
isExportPrivateKey,
|
|
761
|
-
isTxReview
|
|
762
|
-
] = [
|
|
763
|
-
["createAuth", "createPassword", "createPIN"].includes(type),
|
|
764
|
-
["loginAuth", "loginPassword", "loginPIN", "loginOTP", "switchWallets", "loginExternalWallet"].includes(type),
|
|
765
|
-
type === "onRamp",
|
|
766
|
-
type === "oAuth",
|
|
767
|
-
type === "oAuthCallback",
|
|
768
|
-
["telegramLogin", "telegramLoginVerify"].includes(type),
|
|
769
|
-
type === "loginFarcaster",
|
|
770
|
-
type === "addNewCredential",
|
|
771
|
-
type === "switchWallets",
|
|
772
|
-
type === "exportPrivateKey",
|
|
773
|
-
type === "txReview"
|
|
774
|
-
];
|
|
775
|
-
if (isOAuth && !opts.oAuthMethod) {
|
|
776
|
-
throw new Error("oAuthMethod is required for oAuth portal URLs");
|
|
777
|
-
}
|
|
778
|
-
if (isCreate || isLogin) {
|
|
779
|
-
this.assertIsAuthSet();
|
|
780
|
-
}
|
|
781
|
-
let sessionId = opts.sessionId;
|
|
782
|
-
if ((isLogin || isOnRamp || isTelegramLogin || isFarcasterLogin || isExportPrivateKey || isTxReview) && !sessionId) {
|
|
783
|
-
const session = yield this.touchSession(true);
|
|
784
|
-
sessionId = session.sessionId;
|
|
785
|
-
}
|
|
786
|
-
if (!this.loginEncryptionKeyPair) {
|
|
787
|
-
yield this.setLoginEncryptionKeyPair();
|
|
788
|
-
}
|
|
789
|
-
const shouldUseLegacyPortalUrl = opts.useLegacyUrl || !!opts.addNewCredentialPasskeyId || type === "loginAuth";
|
|
790
|
-
const base = type === "onRamp" || isTelegramLogin ? this.ctx.portalUrlOverride || getPortalBaseURL(this.ctx, isTelegramLogin, false, shouldUseLegacyPortalUrl) : yield this.getPortalURL(shouldUseLegacyPortalUrl);
|
|
791
|
-
let path;
|
|
792
|
-
switch (type) {
|
|
793
|
-
case "createPassword": {
|
|
794
|
-
path = `/web/users/${this.userId}/passwords/${opts.pathId}`;
|
|
795
|
-
break;
|
|
796
|
-
}
|
|
797
|
-
case "createPIN": {
|
|
798
|
-
path = `/web/users/${this.userId}/pin/${opts.pathId}`;
|
|
799
|
-
break;
|
|
800
|
-
}
|
|
801
|
-
case "createAuth": {
|
|
802
|
-
path = `/web/users/${this.userId}/biometrics/${opts.pathId}`;
|
|
803
|
-
break;
|
|
804
|
-
}
|
|
805
|
-
case "loginPassword": {
|
|
806
|
-
path = "/web/passwords/login";
|
|
807
|
-
break;
|
|
808
|
-
}
|
|
809
|
-
case "loginAuth": {
|
|
810
|
-
path = "/web/biometrics/login";
|
|
811
|
-
break;
|
|
812
|
-
}
|
|
813
|
-
case "loginPIN": {
|
|
814
|
-
path = "/web/pin/login";
|
|
815
|
-
break;
|
|
816
|
-
}
|
|
817
|
-
case "txReview": {
|
|
818
|
-
path = `/web/users/${this.userId}/transaction-review/${opts.pathId}`;
|
|
819
|
-
break;
|
|
820
|
-
}
|
|
821
|
-
case "onRamp": {
|
|
822
|
-
path = `/web/users/${this.userId}/on-ramp-transaction/v2/${opts.pathId}`;
|
|
823
|
-
break;
|
|
824
|
-
}
|
|
825
|
-
case "telegramLoginVerify": {
|
|
826
|
-
path = `/auth/telegram/verify`;
|
|
827
|
-
break;
|
|
828
|
-
}
|
|
829
|
-
case "telegramLogin": {
|
|
830
|
-
path = `/auth/telegram`;
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
case "oAuth": {
|
|
834
|
-
path = `/auth/${opts.oAuthMethod.toLowerCase()}`;
|
|
835
|
-
break;
|
|
836
|
-
}
|
|
837
|
-
case "oAuthCallback": {
|
|
838
|
-
path = `/auth/${opts.oAuthMethod.toLowerCase()}/callback`;
|
|
839
|
-
break;
|
|
840
|
-
}
|
|
841
|
-
case "loginOTP": {
|
|
842
|
-
path = "/auth/otp";
|
|
843
|
-
break;
|
|
844
|
-
}
|
|
845
|
-
case "loginFarcaster": {
|
|
846
|
-
path = "/auth/farcaster";
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
case "switchWallets": {
|
|
850
|
-
path = `/auth/wallets`;
|
|
851
|
-
break;
|
|
852
|
-
}
|
|
853
|
-
case "addNewCredential": {
|
|
854
|
-
path = "/auth/add-new-credential";
|
|
855
|
-
break;
|
|
856
|
-
}
|
|
857
|
-
case "exportPrivateKey": {
|
|
858
|
-
path = `/web/users/${this.userId}/private-key/${opts.pathId}`;
|
|
859
|
-
break;
|
|
860
|
-
}
|
|
861
|
-
case "loginExternalWallet": {
|
|
862
|
-
path = "/auth/external-wallet";
|
|
863
|
-
break;
|
|
864
|
-
}
|
|
865
|
-
case "connectExternalWallet": {
|
|
866
|
-
path = "/auth/connect-external-wallet";
|
|
867
|
-
break;
|
|
868
|
-
}
|
|
869
|
-
default: {
|
|
870
|
-
throw new Error(`invalid URL type ${type}`);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
let partner = void 0;
|
|
874
|
-
try {
|
|
875
|
-
partner = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
876
|
-
} catch (e) {
|
|
877
|
-
if (this.isPartnerOptional) {
|
|
878
|
-
partner = void 0;
|
|
879
|
-
} else {
|
|
880
|
-
throw e;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
const thisDevice = (_a = opts.thisDevice) != null ? _a : {
|
|
884
|
-
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair),
|
|
885
|
-
sessionId
|
|
886
|
-
};
|
|
887
|
-
const params = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
888
|
-
apiKey: this.ctx.apiKey,
|
|
889
|
-
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
890
|
-
partnerId: partner == null ? void 0 : partner.id
|
|
891
|
-
}, typeof window !== "undefined" && ((_b = window.location) == null ? void 0 : _b.origin) ? { origin: window.location.origin } : {}), {
|
|
892
|
-
portalFont: ((_c = opts.portalTheme) == null ? void 0 : _c.font) || ((_d = this.portalTheme) == null ? void 0 : _d.font) || (partner == null ? void 0 : partner.font),
|
|
893
|
-
portalBorderRadius: ((_e = opts.portalTheme) == null ? void 0 : _e.borderRadius) || ((_f = this.portalTheme) == null ? void 0 : _f.borderRadius),
|
|
894
|
-
portalThemeMode: ((_g = opts.portalTheme) == null ? void 0 : _g.mode) || ((_h = this.portalTheme) == null ? void 0 : _h.mode) || (partner == null ? void 0 : partner.themeMode),
|
|
895
|
-
portalAccentColor: ((_i = opts.portalTheme) == null ? void 0 : _i.accentColor) || ((_j = this.portalTheme) == null ? void 0 : _j.accentColor) || (partner == null ? void 0 : partner.accentColor),
|
|
896
|
-
portalForegroundColor: ((_k = opts.portalTheme) == null ? void 0 : _k.foregroundColor) || ((_l = this.portalTheme) == null ? void 0 : _l.foregroundColor) || (partner == null ? void 0 : partner.foregroundColor),
|
|
897
|
-
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,
|
|
898
|
-
portalPrimaryButtonColor: this.portalPrimaryButtonColor,
|
|
899
|
-
portalTextColor: this.portalTextColor,
|
|
900
|
-
portalPrimaryButtonTextColor: this.portalPrimaryButtonTextColor,
|
|
901
|
-
isForNewDevice: opts.isForNewDevice ? opts.isForNewDevice.toString() : void 0
|
|
902
|
-
}), this.authInfo && (isCreate || isLogin || isAddNewCredential || isOAuthCallback || isSwitchWallets || isExportPrivateKey) ? __spreadProps(__spreadValues({
|
|
903
|
-
authInfo: JSON.stringify(this.authInfo)
|
|
904
|
-
}, isPhone(this.authInfo.auth) ? splitPhoneNumber(this.authInfo.auth.phone) : this.authInfo.auth), {
|
|
905
|
-
pfpUrl: this.authInfo.pfpUrl,
|
|
906
|
-
displayName: this.authInfo.displayName,
|
|
907
|
-
userId: this.userId
|
|
908
|
-
}) : {}), isOnRamp ? { email: this.email } : {}), isLogin || isOAuth || isOAuthCallback || isTelegramLogin || isFarcasterLogin || isAddNewCredential ? __spreadProps(__spreadValues({
|
|
909
|
-
sessionId: thisDevice.sessionId,
|
|
910
|
-
encryptionKey: thisDevice.encryptionKey
|
|
911
|
-
}, opts.newDevice ? {
|
|
912
|
-
newDeviceSessionLookupId: opts.newDevice.sessionId,
|
|
913
|
-
newDeviceEncryptionKey: opts.newDevice.encryptionKey
|
|
914
|
-
} : {}), {
|
|
915
|
-
pregenIds: JSON.stringify(this.pregenIds)
|
|
916
|
-
}) : {}), isOAuth || isOAuthCallback || isFarcasterLogin ? {
|
|
917
|
-
appScheme: opts.appScheme
|
|
918
|
-
} : {}), 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() }), {
|
|
919
|
-
addNewCredentialPasskeyId: opts.addNewCredentialPasskeyId,
|
|
920
|
-
addNewCredentialPasswordId: opts.addNewCredentialPasswordId
|
|
921
|
-
}) : {}), isLogin && {
|
|
922
|
-
// Prior versions won't have this param which will skip the upgrade prompt
|
|
923
|
-
isBasicLoginUpgradeVersion: "true"
|
|
924
|
-
}), isExportPrivateKey || isTxReview ? {
|
|
925
|
-
sessionId: thisDevice.sessionId
|
|
926
|
-
} : {});
|
|
927
|
-
const url = constructUrl({ base, path, params });
|
|
928
|
-
if (opts.shorten) {
|
|
929
|
-
return yield shortenUrl(this.ctx, url, shouldUseLegacyPortalUrl);
|
|
930
|
-
}
|
|
931
|
-
return url;
|
|
827
|
+
return yield __privateGet(this, _portalUrlService).constructPortalUrl(type, opts);
|
|
932
828
|
});
|
|
933
829
|
}
|
|
934
830
|
static resolveEnvironment(env, apiKey) {
|
|
@@ -950,58 +846,182 @@ const _ParaCore = class _ParaCore {
|
|
|
950
846
|
}
|
|
951
847
|
return env;
|
|
952
848
|
}
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
849
|
+
// Create a dedicated interface for #authService
|
|
850
|
+
getAuthServiceInterface() {
|
|
851
|
+
const self2 = this;
|
|
852
|
+
return {
|
|
853
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this),
|
|
854
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
855
|
+
localStorageGetItem: this.localStorageGetItem.bind(this),
|
|
856
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
857
|
+
localStorageRemoveItem: this.localStorageRemoveItem.bind(this),
|
|
858
|
+
isPasskeySupported: this.isPasskeySupported.bind(this),
|
|
859
|
+
getVerificationEmailProps: this.getVerificationEmailProps.bind(this),
|
|
860
|
+
displayModalError: this.displayModalError.bind(this),
|
|
861
|
+
isPortal: this.isPortal.bind(this),
|
|
862
|
+
assertIsLinkingAccount: __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).bind(this),
|
|
863
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
864
|
+
get loginEncryptionKeyPair() {
|
|
865
|
+
return self2.loginEncryptionKeyPair;
|
|
866
|
+
},
|
|
867
|
+
get isNativePasskey() {
|
|
868
|
+
return self2.isNativePasskey;
|
|
869
|
+
},
|
|
870
|
+
ctx: this.ctx,
|
|
871
|
+
get accountLinkInProgress() {
|
|
872
|
+
return self2.accountLinkInProgress;
|
|
873
|
+
},
|
|
874
|
+
partnerId: this.partnerId,
|
|
875
|
+
platformUtils: this.platformUtils,
|
|
876
|
+
externalWalletConnectionOnly: !!this.externalWalletConnectionOnly
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
// Create a dedicated interface for WalletService
|
|
880
|
+
getWalletServiceInterface() {
|
|
881
|
+
const self2 = this;
|
|
882
|
+
return {
|
|
883
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
884
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
885
|
+
isPortal: this.isPortal.bind(this),
|
|
886
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
887
|
+
getBackupKitEmailProps: this.getBackupKitEmailProps.bind(this),
|
|
888
|
+
retrieveSessionCookie: this.retrieveSessionCookie.bind(this),
|
|
889
|
+
isParaConnect: this.isParaConnect.bind(this),
|
|
890
|
+
ctx: this.ctx,
|
|
891
|
+
get partner() {
|
|
892
|
+
return self2.partner;
|
|
893
|
+
},
|
|
894
|
+
platformUtils: this.platformUtils,
|
|
895
|
+
cosmosPrefix: this.cosmosPrefix
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
// Create a dedicated interface for PregenWalletService
|
|
899
|
+
getPregenWalletServiceInterface() {
|
|
900
|
+
var _a;
|
|
901
|
+
const self2 = this;
|
|
902
|
+
return {
|
|
903
|
+
fetchPregenWalletsOverride: (_a = this.fetchPregenWalletsOverride) == null ? void 0 : _a.bind(this),
|
|
904
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
905
|
+
requireApiKey: this.requireApiKey.bind(this),
|
|
906
|
+
getBackupKitEmailProps: this.getBackupKitEmailProps.bind(this),
|
|
907
|
+
isPortal: this.isPortal.bind(this),
|
|
908
|
+
retrieveSessionCookie: this.retrieveSessionCookie.bind(this),
|
|
909
|
+
ctx: this.ctx,
|
|
910
|
+
platformUtils: this.platformUtils,
|
|
911
|
+
get partner() {
|
|
912
|
+
return self2.partner;
|
|
961
913
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
// Create a dedicated interface for PortalUrlService
|
|
917
|
+
getPortalUrlServiceInterface() {
|
|
918
|
+
const self2 = this;
|
|
919
|
+
return {
|
|
920
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
921
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
922
|
+
isPortal: this.isPortal.bind(this),
|
|
923
|
+
isPartnerOptional: this.isPartnerOptional,
|
|
924
|
+
ctx: this.ctx,
|
|
925
|
+
get loginEncryptionKeyPair() {
|
|
926
|
+
return self2.loginEncryptionKeyPair;
|
|
927
|
+
},
|
|
928
|
+
get portalTheme() {
|
|
929
|
+
return self2.portalTheme;
|
|
930
|
+
},
|
|
931
|
+
get portalPrimaryButtonColor() {
|
|
932
|
+
return self2.portalPrimaryButtonColor;
|
|
933
|
+
},
|
|
934
|
+
get portalTextColor() {
|
|
935
|
+
return self2.portalTextColor;
|
|
936
|
+
},
|
|
937
|
+
get portalPrimaryButtonTextColor() {
|
|
938
|
+
return self2.portalPrimaryButtonTextColor;
|
|
939
|
+
},
|
|
940
|
+
get portalBackgroundColor() {
|
|
941
|
+
return self2.portalBackgroundColor;
|
|
942
|
+
},
|
|
943
|
+
get accountLinkInProgress() {
|
|
944
|
+
return self2.accountLinkInProgress;
|
|
968
945
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
|
|
999
|
-
}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
// Create a dedicated interface for SessionManagementService
|
|
949
|
+
getSessionManagementServiceInterface() {
|
|
950
|
+
const self2 = this;
|
|
951
|
+
return {
|
|
952
|
+
displayModalError: this.displayModalError.bind(this),
|
|
953
|
+
setLoginEncryptionKeyPair: this.setLoginEncryptionKeyPair.bind(this),
|
|
954
|
+
initializeWorker: this.initializeWorker.bind(this),
|
|
955
|
+
isPortal: this.isPortal.bind(this),
|
|
956
|
+
getPartner: this.getPartner.bind(this),
|
|
957
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
958
|
+
platformUtils: this.platformUtils,
|
|
959
|
+
ctx: this.ctx,
|
|
960
|
+
get loginEncryptionKeyPair() {
|
|
961
|
+
return self2.loginEncryptionKeyPair;
|
|
962
|
+
},
|
|
963
|
+
get partner() {
|
|
964
|
+
return self2.partner;
|
|
965
|
+
},
|
|
966
|
+
get isWorkerInitialized() {
|
|
967
|
+
return self2.isWorkerInitialized;
|
|
968
|
+
},
|
|
969
|
+
get isReady() {
|
|
970
|
+
return self2.isReady;
|
|
971
|
+
},
|
|
972
|
+
isNoWalletConfig: this.isNoWalletConfig,
|
|
973
|
+
get isSwitchingWallets() {
|
|
974
|
+
return self2.isSwitchingWallets;
|
|
1000
975
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
getStateMachineInterface() {
|
|
979
|
+
const self2 = this;
|
|
980
|
+
return {
|
|
981
|
+
setup: this.setup.bind(this),
|
|
982
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this),
|
|
983
|
+
isPortal: this.isPortal.bind(this),
|
|
984
|
+
setupAfterLogin: this.setupAfterLogin.bind(this),
|
|
985
|
+
devLog: this.devLog.bind(this),
|
|
986
|
+
authService: __privateGet(this, _authService),
|
|
987
|
+
walletService: __privateGet(this, _walletService),
|
|
988
|
+
pregenWalletService: __privateGet(this, _pregenWalletService),
|
|
989
|
+
pollingService: __privateGet(this, _pollingService),
|
|
990
|
+
externalWalletService: __privateGet(this, _externalWalletService),
|
|
991
|
+
sessionManagementService: __privateGet(this, _sessionManagementService),
|
|
992
|
+
portalUrlService: __privateGet(this, _portalUrlService),
|
|
993
|
+
get isNoWalletConfig() {
|
|
994
|
+
return self2.isNoWalletConfig;
|
|
1003
995
|
}
|
|
1004
|
-
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
// Create a dedicated interface for ExternalWalletService
|
|
999
|
+
getExternalWalletServiceInterface() {
|
|
1000
|
+
return {
|
|
1001
|
+
assertPartner: __privateMethod(this, _ParaCore_instances, assertPartner_fn).bind(this),
|
|
1002
|
+
localStorageSetItem: this.localStorageSetItem.bind(this),
|
|
1003
|
+
logout: __privateMethod(this, _ParaCore_instances, logout_fn).bind(this)
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
// Create a dedicated interface for PollingService
|
|
1007
|
+
getPollingServiceInterface() {
|
|
1008
|
+
const self2 = this;
|
|
1009
|
+
return {
|
|
1010
|
+
isPortal: this.isPortal.bind(this),
|
|
1011
|
+
devLog: this.devLog.bind(this),
|
|
1012
|
+
get popupWindow() {
|
|
1013
|
+
return self2.popupWindow;
|
|
1014
|
+
},
|
|
1015
|
+
set popupWindow(w) {
|
|
1016
|
+
self2.popupWindow = w;
|
|
1017
|
+
},
|
|
1018
|
+
platformUtils: this.platformUtils,
|
|
1019
|
+
ctx: this.ctx
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
touchSession(regenerate = false) {
|
|
1023
|
+
return __async(this, null, function* () {
|
|
1024
|
+
return __privateGet(this, _sessionManagementService).touchSession(regenerate);
|
|
1005
1025
|
});
|
|
1006
1026
|
}
|
|
1007
1027
|
getVerificationEmailProps() {
|
|
@@ -1034,7 +1054,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1034
1054
|
init() {
|
|
1035
1055
|
return __async(this, null, function* () {
|
|
1036
1056
|
var _a, _b;
|
|
1037
|
-
this.userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1057
|
+
__privateGet(this, _authService).userId = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_USER_ID)) || void 0;
|
|
1038
1058
|
const storageAuthInfo = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_AUTH_INFO)) || void 0;
|
|
1039
1059
|
const stringExternalWallets = yield this.localStorageGetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS);
|
|
1040
1060
|
const _externalWallets = JSON.parse(stringExternalWallets || "{}");
|
|
@@ -1052,7 +1072,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1052
1072
|
};
|
|
1053
1073
|
authInfo = __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, authParams);
|
|
1054
1074
|
}
|
|
1055
|
-
|
|
1075
|
+
__privateGet(this, _authService).authInfo = authInfo;
|
|
1056
1076
|
const stringWallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_WALLETS);
|
|
1057
1077
|
const _wallets = JSON.parse(stringWallets || "{}");
|
|
1058
1078
|
const stringEd25519Wallets = this.platformUtils.secureStorage ? yield this.platformUtils.secureStorage.get(constants.LOCAL_STORAGE_ED25519_WALLETS) : yield this.localStorageGetItem(constants.LOCAL_STORAGE_ED25519_WALLETS);
|
|
@@ -1076,8 +1096,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1076
1096
|
}, {}) : fromJson;
|
|
1077
1097
|
})();
|
|
1078
1098
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
1079
|
-
this.sessionCookie = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1080
|
-
if (Object.values(this.wallets).filter((w) => this.isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1099
|
+
__privateGet(this, _sessionManagementService).sessionCookie = (yield this.localStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || (yield this.sessionStorageGetItem(constants.LOCAL_STORAGE_SESSION_COOKIE)) || void 0;
|
|
1100
|
+
if (Object.values(this.wallets).filter((w) => __privateGet(this, _walletService).isWalletOwned(w)).length > 0 && this.currentWalletIdsArray.length === 0) {
|
|
1081
1101
|
this.findWalletId(void 0, { forbidPregen: true });
|
|
1082
1102
|
}
|
|
1083
1103
|
const loginEncryptionKey = yield this.sessionStorageGetItem(constants.SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR);
|
|
@@ -1094,12 +1114,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1094
1114
|
}
|
|
1095
1115
|
setAuth(_0) {
|
|
1096
1116
|
return __async(this, arguments, function* (auth, { extras = {}, userId } = {}) {
|
|
1097
|
-
|
|
1098
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
1099
|
-
if (!!userId) {
|
|
1100
|
-
yield this.setUserId(userId);
|
|
1101
|
-
}
|
|
1102
|
-
return __privateGet(this, _authInfo);
|
|
1117
|
+
return yield __privateGet(this, _authService).setAuth(auth, { extras, userId });
|
|
1103
1118
|
});
|
|
1104
1119
|
}
|
|
1105
1120
|
/**
|
|
@@ -1111,40 +1126,11 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1111
1126
|
this.setModalError(error);
|
|
1112
1127
|
}
|
|
1113
1128
|
}
|
|
1114
|
-
/**
|
|
1115
|
-
* Handle specific touchSession errors with user-friendly messages
|
|
1116
|
-
* @private
|
|
1117
|
-
*/
|
|
1118
|
-
handleTouchSessionError(error) {
|
|
1119
|
-
const errorStr = String(error);
|
|
1120
|
-
const errorMessage = error instanceof Error ? error.message : "";
|
|
1121
|
-
if (errorStr.includes("blocked by CORS policy") && errorStr.includes("Access-Control-Allow-Origin")) {
|
|
1122
|
-
const message = "Request rate limit reached. Please wait a couple of minutes and try again.";
|
|
1123
|
-
console.error(`[Para] ${message}`);
|
|
1124
|
-
this.displayModalError(message);
|
|
1125
|
-
return;
|
|
1126
|
-
}
|
|
1127
|
-
if (error.status === 403 && errorMessage.includes("origin not authorized")) {
|
|
1128
|
-
this.displayModalError(
|
|
1129
|
-
"The current origin is not allowed. Update your allowed origins in the Para developer portal to allow the current origin."
|
|
1130
|
-
);
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
1129
|
assertUserId({ allowGuestMode = false } = {}) {
|
|
1135
|
-
|
|
1136
|
-
throw new Error("no userId is set");
|
|
1137
|
-
}
|
|
1138
|
-
return this.userId;
|
|
1130
|
+
return __privateGet(this, _authService).assertUserId({ allowGuestMode });
|
|
1139
1131
|
}
|
|
1140
1132
|
assertIsAuthSet(allowed) {
|
|
1141
|
-
|
|
1142
|
-
throw new Error("auth is not set");
|
|
1143
|
-
}
|
|
1144
|
-
if (allowed && !allowed.includes(__privateGet(this, _authInfo).authType)) {
|
|
1145
|
-
throw new Error(`invalid auth type, expected ${allowed.join(", ")}`);
|
|
1146
|
-
}
|
|
1147
|
-
return __privateGet(this, _authInfo);
|
|
1133
|
+
return __privateGet(this, _authService).assertIsAuthSet(allowed);
|
|
1148
1134
|
}
|
|
1149
1135
|
/**
|
|
1150
1136
|
* Sets the email associated with the `ParaCore` instance.
|
|
@@ -1152,7 +1138,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1152
1138
|
*/
|
|
1153
1139
|
setEmail(email) {
|
|
1154
1140
|
return __async(this, null, function* () {
|
|
1155
|
-
yield this.setAuth({ email });
|
|
1141
|
+
yield __privateGet(this, _authService).setAuth({ email });
|
|
1156
1142
|
});
|
|
1157
1143
|
}
|
|
1158
1144
|
/**
|
|
@@ -1161,7 +1147,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1161
1147
|
*/
|
|
1162
1148
|
setTelegramUserId(telegramUserId) {
|
|
1163
1149
|
return __async(this, null, function* () {
|
|
1164
|
-
yield this.setAuth({ telegramUserId });
|
|
1150
|
+
yield __privateGet(this, _authService).setAuth({ telegramUserId });
|
|
1165
1151
|
});
|
|
1166
1152
|
}
|
|
1167
1153
|
/**
|
|
@@ -1171,7 +1157,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1171
1157
|
*/
|
|
1172
1158
|
setPhoneNumber(phone, countryCode) {
|
|
1173
1159
|
return __async(this, null, function* () {
|
|
1174
|
-
yield this.setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
1160
|
+
yield __privateGet(this, _authService).setAuth({ phone: formatPhoneNumber(phone, countryCode) });
|
|
1175
1161
|
});
|
|
1176
1162
|
}
|
|
1177
1163
|
/**
|
|
@@ -1180,7 +1166,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1180
1166
|
*/
|
|
1181
1167
|
setFarcasterUsername(farcasterUsername) {
|
|
1182
1168
|
return __async(this, null, function* () {
|
|
1183
|
-
yield this.setAuth({ farcasterUsername });
|
|
1169
|
+
yield __privateGet(this, _authService).setAuth({ farcasterUsername });
|
|
1184
1170
|
});
|
|
1185
1171
|
}
|
|
1186
1172
|
/**
|
|
@@ -1190,75 +1176,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1190
1176
|
*/
|
|
1191
1177
|
setExternalWallet(externalWallet) {
|
|
1192
1178
|
return __async(this, null, function* () {
|
|
1193
|
-
|
|
1194
|
-
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
1195
|
-
(acc, {
|
|
1196
|
-
partnerId: wPartnerId,
|
|
1197
|
-
address,
|
|
1198
|
-
type,
|
|
1199
|
-
provider,
|
|
1200
|
-
providerId,
|
|
1201
|
-
addressBech32,
|
|
1202
|
-
withFullParaAuth,
|
|
1203
|
-
isConnectionOnly,
|
|
1204
|
-
withVerification
|
|
1205
|
-
}) => {
|
|
1206
|
-
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
1207
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1208
|
-
[address]: {
|
|
1209
|
-
id: address,
|
|
1210
|
-
partnerId,
|
|
1211
|
-
address: addressBech32 != null ? addressBech32 : address,
|
|
1212
|
-
type,
|
|
1213
|
-
name: provider,
|
|
1214
|
-
isExternal: true,
|
|
1215
|
-
isExternalWithParaAuth: withFullParaAuth,
|
|
1216
|
-
externalProviderId: providerId,
|
|
1217
|
-
signer: "",
|
|
1218
|
-
isExternalConnectionOnly: isConnectionOnly,
|
|
1219
|
-
isExternalWithVerification: withVerification
|
|
1220
|
-
}
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
return acc;
|
|
1224
|
-
},
|
|
1225
|
-
{}
|
|
1226
|
-
), this.setExternalWallets(this.externalWallets);
|
|
1227
|
-
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1179
|
+
return yield __privateGet(this, _externalWalletService).setExternalWallet({ externalWallet });
|
|
1228
1180
|
});
|
|
1229
1181
|
}
|
|
1230
1182
|
addExternalWallets(externalWallets) {
|
|
1231
1183
|
return __async(this, null, function* () {
|
|
1232
|
-
|
|
1233
|
-
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
1234
|
-
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
1235
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1236
|
-
[address]: wallet
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
return acc;
|
|
1240
|
-
}, {})), externalWallets.reduce(
|
|
1241
|
-
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
1242
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
1243
|
-
[address]: {
|
|
1244
|
-
id: address,
|
|
1245
|
-
partnerId,
|
|
1246
|
-
address: addressBech32 != null ? addressBech32 : address,
|
|
1247
|
-
type,
|
|
1248
|
-
name: provider,
|
|
1249
|
-
isExternal: true,
|
|
1250
|
-
isExternalWithParaAuth: withFullParaAuth,
|
|
1251
|
-
externalProviderId: providerId,
|
|
1252
|
-
signer: "",
|
|
1253
|
-
isExternalConnectionOnly: isConnectionOnly,
|
|
1254
|
-
isExternalWithVerification: withVerification
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
},
|
|
1258
|
-
{}
|
|
1259
|
-
));
|
|
1260
|
-
this.setExternalWallets(this.externalWallets);
|
|
1261
|
-
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
1184
|
+
return yield __privateGet(this, _externalWalletService).addExternalWallets({ externalWallets });
|
|
1262
1185
|
});
|
|
1263
1186
|
}
|
|
1264
1187
|
/**
|
|
@@ -1267,8 +1190,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1267
1190
|
*/
|
|
1268
1191
|
setUserId(userId) {
|
|
1269
1192
|
return __async(this, null, function* () {
|
|
1270
|
-
this.userId
|
|
1271
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_USER_ID, userId);
|
|
1193
|
+
return yield __privateGet(this, _authService).setUserId(userId);
|
|
1272
1194
|
});
|
|
1273
1195
|
}
|
|
1274
1196
|
/**
|
|
@@ -1277,12 +1199,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1277
1199
|
*/
|
|
1278
1200
|
setWallets(wallets) {
|
|
1279
1201
|
return __async(this, null, function* () {
|
|
1280
|
-
this.wallets
|
|
1281
|
-
if (this.platformUtils.secureStorage) {
|
|
1282
|
-
yield this.platformUtils.secureStorage.set(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_WALLETS, JSON.stringify(wallets));
|
|
1202
|
+
return yield __privateGet(this, _walletService).setWallets(wallets);
|
|
1286
1203
|
});
|
|
1287
1204
|
}
|
|
1288
1205
|
/**
|
|
@@ -1291,12 +1208,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1291
1208
|
*/
|
|
1292
1209
|
setExternalWallets(externalWallets) {
|
|
1293
1210
|
return __async(this, null, function* () {
|
|
1294
|
-
|
|
1295
|
-
this.externalWallets = externalWallets(this.externalWallets);
|
|
1296
|
-
} else {
|
|
1297
|
-
this.externalWallets = externalWallets;
|
|
1298
|
-
}
|
|
1299
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(this.externalWallets));
|
|
1211
|
+
return yield __privateGet(this, _externalWalletService).setExternalWallets({ externalWallets });
|
|
1300
1212
|
});
|
|
1301
1213
|
}
|
|
1302
1214
|
/**
|
|
@@ -1323,51 +1235,36 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1323
1235
|
* @returns - userId associated with the `ParaCore` instance.
|
|
1324
1236
|
*/
|
|
1325
1237
|
getUserId() {
|
|
1326
|
-
|
|
1238
|
+
var _a;
|
|
1239
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.userId;
|
|
1327
1240
|
}
|
|
1328
1241
|
getAuthInfo() {
|
|
1329
|
-
|
|
1242
|
+
var _a;
|
|
1243
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.authInfo;
|
|
1330
1244
|
}
|
|
1331
1245
|
/**
|
|
1332
1246
|
* Gets the email associated with the `ParaCore` instance.
|
|
1333
1247
|
* @returns - email associated with the `ParaCore` instance.
|
|
1334
1248
|
*/
|
|
1335
1249
|
getEmail() {
|
|
1336
|
-
|
|
1250
|
+
var _a;
|
|
1251
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.email;
|
|
1337
1252
|
}
|
|
1338
1253
|
/**
|
|
1339
1254
|
* Gets the formatted phone number associated with the `ParaCore` instance.
|
|
1340
1255
|
* @returns - formatted phone number associated with the `ParaCore` instance.
|
|
1341
1256
|
*/
|
|
1342
1257
|
getPhoneNumber() {
|
|
1343
|
-
|
|
1258
|
+
var _a;
|
|
1259
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.phone;
|
|
1344
1260
|
}
|
|
1345
1261
|
/**
|
|
1346
1262
|
* Gets the farcaster username associated with the `ParaCore` instance.
|
|
1347
1263
|
* @returns - farcaster username associated with the `ParaCore` instance.
|
|
1348
1264
|
*/
|
|
1349
1265
|
getFarcasterUsername() {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
setCurrentWalletIds(_0) {
|
|
1353
|
-
return __async(this, arguments, function* (currentWalletIds, {
|
|
1354
|
-
needsWallet = false,
|
|
1355
|
-
sessionLookupId,
|
|
1356
|
-
newDeviceSessionLookupId
|
|
1357
|
-
} = {}) {
|
|
1358
|
-
this.currentWalletIds = currentWalletIds;
|
|
1359
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_CURRENT_WALLET_IDS, JSON.stringify(this.currentWalletIds));
|
|
1360
|
-
if (sessionLookupId) {
|
|
1361
|
-
yield this.ctx.client.setCurrentWalletIds(
|
|
1362
|
-
this.getUserId(),
|
|
1363
|
-
this.currentWalletIds,
|
|
1364
|
-
needsWallet,
|
|
1365
|
-
sessionLookupId,
|
|
1366
|
-
newDeviceSessionLookupId
|
|
1367
|
-
);
|
|
1368
|
-
}
|
|
1369
|
-
dispatchEvent(ParaEvent.WALLETS_CHANGE_EVENT, null);
|
|
1370
|
-
});
|
|
1266
|
+
var _a;
|
|
1267
|
+
return (_a = __privateGet(this, _authService)) == null ? void 0 : _a.farcasterUsername;
|
|
1371
1268
|
}
|
|
1372
1269
|
/**
|
|
1373
1270
|
* Fetches the most recent OAuth account metadata for the signed-in user.
|
|
@@ -1385,29 +1282,6 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1385
1282
|
return accountMetadata;
|
|
1386
1283
|
});
|
|
1387
1284
|
}
|
|
1388
|
-
/**
|
|
1389
|
-
* Validates that a wallet ID is present on the instance, usable, and matches the desired filters.
|
|
1390
|
-
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
1391
|
-
* @param {string} [walletId] the wallet ID to validate.
|
|
1392
|
-
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
1393
|
-
* @returns {string} the wallet ID originally passed, or the one found.
|
|
1394
|
-
*/
|
|
1395
|
-
findWalletId(walletId, filter = {}) {
|
|
1396
|
-
if (walletId) {
|
|
1397
|
-
this.assertIsValidWalletId(walletId, filter);
|
|
1398
|
-
} else {
|
|
1399
|
-
for (const id of [...this.currentWalletIdsUnique, ...Object.keys(this.wallets)]) {
|
|
1400
|
-
if (this.isWalletUsable(id, filter)) {
|
|
1401
|
-
walletId = id;
|
|
1402
|
-
break;
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
if (!walletId) {
|
|
1406
|
-
throw new Error(`no valid wallet id found`);
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
return walletId;
|
|
1410
|
-
}
|
|
1411
1285
|
/**
|
|
1412
1286
|
* Retrieves a wallet with the given address, if present.
|
|
1413
1287
|
* If no ID is passed, this will instead return the first valid, usable wallet ID that matches the filters.
|
|
@@ -1415,78 +1289,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1415
1289
|
* @param {WalletFilters} [filter={}] a `WalletFilters` object specifying allowed types, schemes, and whether to forbid unclaimed pregen wallets.
|
|
1416
1290
|
* @returns {string} the wallet ID originally passed, or the one found.
|
|
1417
1291
|
*/
|
|
1418
|
-
findWalletByAddress(
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
const pregenWalletIds = Object.keys(this.wallets).filter(
|
|
1425
|
-
(id) => this.wallets[id].type === type && this.isPregenWalletClaimable(this.wallets[id])
|
|
1426
|
-
);
|
|
1427
|
-
[...walletIds, ...pregenWalletIds].forEach((id) => {
|
|
1428
|
-
if (address.toLowerCase() === this.getDisplayAddress(id, { addressType: type }).toLowerCase()) {
|
|
1429
|
-
wallet = this.wallets[id];
|
|
1430
|
-
}
|
|
1431
|
-
});
|
|
1432
|
-
});
|
|
1433
|
-
if (!wallet) {
|
|
1434
|
-
throw new Error(`wallet with address ${address} not found`);
|
|
1435
|
-
}
|
|
1436
|
-
this.assertIsValidWalletId(wallet.id, filter);
|
|
1437
|
-
return wallet;
|
|
1438
|
-
}
|
|
1439
|
-
findWallet(idOrAddress, overrideType, filter = {}) {
|
|
1440
|
-
var _a, _c, _d;
|
|
1441
|
-
if (!this.isExternalWalletAuth) {
|
|
1442
|
-
if (!idOrAddress && Object.keys(this.externalWallets).length > 0) {
|
|
1443
|
-
return Object.values(this.externalWallets)[0];
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
if ((_a = this.externalWallets) == null ? void 0 : _a[idOrAddress]) {
|
|
1447
|
-
return this.externalWallets[idOrAddress];
|
|
1448
|
-
}
|
|
1449
|
-
try {
|
|
1450
|
-
const walletId = this.findWalletId(idOrAddress, filter);
|
|
1451
|
-
if (walletId && !!this.wallets[walletId]) {
|
|
1452
|
-
const _b = this.wallets[walletId], { signer: _signer } = _b, wallet = __objRest(_b, ["signer"]);
|
|
1453
|
-
const type = (_d = overrideType != null ? overrideType : (_c = this.currentWalletIdsArray.find(([id]) => id === walletId)) == null ? void 0 : _c[1]) != null ? _d : wallet.type;
|
|
1454
|
-
return __spreadProps(__spreadValues({}, wallet), {
|
|
1455
|
-
type
|
|
1456
|
-
});
|
|
1457
|
-
}
|
|
1458
|
-
} catch (e) {
|
|
1459
|
-
return void 0;
|
|
1460
|
-
}
|
|
1292
|
+
findWalletByAddress(...params) {
|
|
1293
|
+
return __privateGet(this, _walletService).findWalletByAddress(...params);
|
|
1294
|
+
}
|
|
1295
|
+
findWallet(...params) {
|
|
1296
|
+
const [walletId, walletType, filters = {}] = params;
|
|
1297
|
+
return __privateGet(this, _walletService).findWallet(walletId, walletType, filters);
|
|
1461
1298
|
}
|
|
1462
1299
|
get availableWallets() {
|
|
1463
|
-
|
|
1464
|
-
return [
|
|
1465
|
-
...[...this.currentWalletIdsArray, ...__privateGet(this, _ParaCore_instances, guestWalletIdsArray_get)].map(([address, type]) => [address, type, false]).map(([id, type]) => {
|
|
1466
|
-
const wallet = this.findWallet(id, type);
|
|
1467
|
-
if (!wallet) return null;
|
|
1468
|
-
const name = wallet.name;
|
|
1469
|
-
const address = this.getDisplayAddress(id, { addressType: type });
|
|
1470
|
-
const addressShort = this.getDisplayAddress(id, { addressType: type, truncate: true });
|
|
1471
|
-
return {
|
|
1472
|
-
id: wallet.id,
|
|
1473
|
-
partner: wallet.partner,
|
|
1474
|
-
type,
|
|
1475
|
-
address,
|
|
1476
|
-
name,
|
|
1477
|
-
addressShort,
|
|
1478
|
-
displayName: name != null ? name : addressShort,
|
|
1479
|
-
ensName: wallet.ensName,
|
|
1480
|
-
ensAvatar: wallet.ensAvatar
|
|
1481
|
-
};
|
|
1482
|
-
}).filter((obj) => obj !== null),
|
|
1483
|
-
...Object.values((_a = this.externalWallets) != null ? _a : {}).map((wallet) => {
|
|
1484
|
-
return __spreadProps(__spreadValues({}, wallet), {
|
|
1485
|
-
addressShort: truncateAddress(wallet.address, wallet.type, { prefix: this.cosmosPrefix }),
|
|
1486
|
-
displayName: wallet.externalProviderId
|
|
1487
|
-
});
|
|
1488
|
-
})
|
|
1489
|
-
];
|
|
1300
|
+
return __privateGet(this, _walletService).availableWallets;
|
|
1490
1301
|
}
|
|
1491
1302
|
/**
|
|
1492
1303
|
* Retrieves all usable wallets with the provided type (`'EVM' | 'COSMOS' | 'SOLANA'`)
|
|
@@ -1494,52 +1305,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1494
1305
|
* @returns {Wallet[]} an array of matching wallets.
|
|
1495
1306
|
*/
|
|
1496
1307
|
getWalletsByType(type) {
|
|
1497
|
-
return
|
|
1498
|
-
}
|
|
1499
|
-
assertIsValidWalletId(walletId, condition = {}) {
|
|
1500
|
-
this.isWalletUsable(walletId, condition, true);
|
|
1501
|
-
}
|
|
1502
|
-
assertIsValidWalletType(type, walletTypes) {
|
|
1503
|
-
return __async(this, null, function* () {
|
|
1504
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1505
|
-
if (!type || !WALLET_TYPES.includes(type) || !(walletTypes != null ? walletTypes : supportedWalletTypes.map(({ type: type2 }) => type2)).includes(type)) {
|
|
1506
|
-
throw new Error(`wallet type ${type} is not supported`);
|
|
1507
|
-
}
|
|
1508
|
-
return type;
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
getMissingTypes() {
|
|
1512
|
-
return __async(this, null, function* () {
|
|
1513
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1514
|
-
return supportedWalletTypes.filter(
|
|
1515
|
-
({ type: t, optional }) => !optional && Object.values(this.wallets).every((w) => !this.isWalletOwned(w) || !WalletSchemeTypeMap[w.scheme][t])
|
|
1516
|
-
).map(({ type }) => type);
|
|
1517
|
-
});
|
|
1518
|
-
}
|
|
1519
|
-
getTypesToCreate(types) {
|
|
1520
|
-
return __async(this, null, function* () {
|
|
1521
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1522
|
-
return getSchemes(types != null ? types : yield this.getMissingTypes()).map((scheme) => {
|
|
1523
|
-
switch (scheme) {
|
|
1524
|
-
case "ED25519":
|
|
1525
|
-
return "SOLANA";
|
|
1526
|
-
default:
|
|
1527
|
-
return supportedWalletTypes.some(({ type, optional }) => type === "COSMOS" && !optional) ? "COSMOS" : "EVM";
|
|
1528
|
-
}
|
|
1529
|
-
});
|
|
1530
|
-
});
|
|
1308
|
+
return __privateGet(this, _walletService).getWalletsByType(type);
|
|
1531
1309
|
}
|
|
1532
|
-
|
|
1310
|
+
getPartner(partnerId) {
|
|
1533
1311
|
return __async(this, null, function* () {
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
return portalUrl;
|
|
1537
|
-
} catch (e) {
|
|
1538
|
-
if (this.isPartnerOptional) {
|
|
1539
|
-
return void 0;
|
|
1540
|
-
}
|
|
1541
|
-
throw e;
|
|
1312
|
+
if (this.isPartnerOptional && !partnerId) {
|
|
1313
|
+
return void 0;
|
|
1542
1314
|
}
|
|
1315
|
+
const res = yield this.ctx.client.getPartner(partnerId);
|
|
1316
|
+
this.partner = res.data.partner;
|
|
1317
|
+
return this.partner;
|
|
1543
1318
|
});
|
|
1544
1319
|
}
|
|
1545
1320
|
/**
|
|
@@ -1549,7 +1324,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1549
1324
|
*/
|
|
1550
1325
|
getPortalURL(isLegacy) {
|
|
1551
1326
|
return __async(this, null, function* () {
|
|
1552
|
-
return
|
|
1327
|
+
return yield __privateGet(this, _portalUrlService).getPortalURL(isLegacy);
|
|
1553
1328
|
});
|
|
1554
1329
|
}
|
|
1555
1330
|
/**
|
|
@@ -1582,33 +1357,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1582
1357
|
*/
|
|
1583
1358
|
fetchWallets() {
|
|
1584
1359
|
return __async(this, null, function* () {
|
|
1585
|
-
|
|
1586
|
-
return res.data.wallets.filter(
|
|
1587
|
-
(wallet) => !!wallet.address && wallet.sharesPersisted && (this.isParaConnect() || !this.isParaConnect() && this.isWalletSupported(entityToWallet(wallet)))
|
|
1588
|
-
);
|
|
1360
|
+
return yield __privateGet(this, _walletService).fetchWallets();
|
|
1589
1361
|
});
|
|
1590
1362
|
}
|
|
1591
1363
|
populateWalletAddresses() {
|
|
1592
1364
|
return __async(this, null, function* () {
|
|
1593
|
-
|
|
1594
|
-
const wallets = res.data.wallets;
|
|
1595
|
-
wallets.forEach((entity) => {
|
|
1596
|
-
if (this.wallets[entity.id]) {
|
|
1597
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
1598
|
-
}
|
|
1599
|
-
});
|
|
1600
|
-
yield this.setWallets(this.wallets);
|
|
1601
|
-
});
|
|
1602
|
-
}
|
|
1603
|
-
populatePregenWalletAddresses() {
|
|
1604
|
-
return __async(this, null, function* () {
|
|
1605
|
-
const res = yield this.getPregenWallets();
|
|
1606
|
-
res.forEach((entity) => {
|
|
1607
|
-
if (this.wallets[entity.id]) {
|
|
1608
|
-
this.wallets[entity.id] = __spreadValues(__spreadValues({}, entityToWallet(entity)), this.wallets[entity.id]);
|
|
1609
|
-
}
|
|
1610
|
-
});
|
|
1611
|
-
yield this.setWallets(this.wallets);
|
|
1365
|
+
return yield __privateGet(this, _walletService).populateWalletAddresses();
|
|
1612
1366
|
});
|
|
1613
1367
|
}
|
|
1614
1368
|
/**
|
|
@@ -1618,91 +1372,39 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1618
1372
|
* @param {TWalletType} opts.type type of external wallet to use for identification.
|
|
1619
1373
|
* @param {string} opts.provider the name of the provider for the external wallet.
|
|
1620
1374
|
*/
|
|
1621
|
-
loginExternalWallet(
|
|
1375
|
+
loginExternalWallet(params) {
|
|
1622
1376
|
return __async(this, null, function* () {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
yield this.ctx.client.trackExternalWalletConnections({
|
|
1635
|
-
wallets: externalWallets.map((wallet) => ({
|
|
1636
|
-
address: wallet.address,
|
|
1637
|
-
type: wallet.type,
|
|
1638
|
-
provider: wallet.provider
|
|
1639
|
-
}))
|
|
1640
|
-
});
|
|
1641
|
-
} catch (err) {
|
|
1642
|
-
console.error("Error tracking external wallet connections:", err);
|
|
1643
|
-
}
|
|
1644
|
-
if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
|
|
1645
|
-
yield this.addExternalWallets(
|
|
1646
|
-
externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
|
|
1647
|
-
withFullParaAuth: false
|
|
1648
|
-
}))
|
|
1649
|
-
);
|
|
1650
|
-
return Promise.resolve({
|
|
1651
|
-
userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
if (Array.isArray(externalWallet)) {
|
|
1655
|
-
throw new Error(
|
|
1656
|
-
"Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
|
|
1657
|
-
);
|
|
1658
|
-
}
|
|
1659
|
-
this.requireApiKey();
|
|
1660
|
-
const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet, chainId, uri });
|
|
1661
|
-
if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
|
|
1662
|
-
yield this.touchSession(true);
|
|
1663
|
-
}
|
|
1664
|
-
if (externalWallet.withFullParaAuth) {
|
|
1665
|
-
yield this.ctx.client.sessionAddPortalVerification();
|
|
1666
|
-
}
|
|
1667
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1377
|
+
return yield __privateGet(this, _authService).loginExternalWallet(params);
|
|
1378
|
+
});
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Connects to an external wallet & logs in to Para (if applicable).
|
|
1382
|
+
* @param {Object} params the params object
|
|
1383
|
+
* @param {Function} params.connect the function called to connect to the external wallet.
|
|
1384
|
+
*/
|
|
1385
|
+
connectExternalWallet(params) {
|
|
1386
|
+
return __async(this, null, function* () {
|
|
1387
|
+
return yield __privateGet(this, _authService).connectExternalWallet(params);
|
|
1668
1388
|
});
|
|
1669
1389
|
}
|
|
1670
1390
|
verifyExternalWallet(params) {
|
|
1671
1391
|
return __async(this, null, function* () {
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
signedMessage,
|
|
1684
|
-
cosmosPublicKeyHex,
|
|
1685
|
-
cosmosSigner
|
|
1686
|
-
});
|
|
1687
|
-
serverAuthState = _serverAuthState;
|
|
1688
|
-
urlOptions = rest;
|
|
1689
|
-
}
|
|
1690
|
-
if (serverAuthState.stage === "login" && ((_c = serverAuthState.loginAuthMethods) == null ? void 0 : _c.includes(AuthMethod.PIN))) {
|
|
1691
|
-
const { sessionLookupId } = yield this.touchSession();
|
|
1692
|
-
return yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1693
|
-
}
|
|
1694
|
-
let state;
|
|
1695
|
-
try {
|
|
1696
|
-
state = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
1697
|
-
} catch (err) {
|
|
1698
|
-
console.error("Error prepping state:", err);
|
|
1699
|
-
}
|
|
1700
|
-
return state;
|
|
1392
|
+
return yield __privateGet(this, _authService).verifyExternalWallet(params);
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
retryVerifyExternalWallet() {
|
|
1396
|
+
return __async(this, null, function* () {
|
|
1397
|
+
return yield __privateGet(this, _authService).retryVerifyExternalWallet();
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
signExternalWalletVerification(params) {
|
|
1401
|
+
return __async(this, null, function* () {
|
|
1402
|
+
return yield __privateGet(this, _authService).signExternalWalletVerification(params);
|
|
1701
1403
|
});
|
|
1702
1404
|
}
|
|
1703
1405
|
verifyExternalWalletLink(opts) {
|
|
1704
1406
|
return __async(this, null, function* () {
|
|
1705
|
-
const accountLinkInProgress =
|
|
1407
|
+
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EXTERNAL_WALLET"]);
|
|
1706
1408
|
if (!accountLinkInProgress.externalWallet) {
|
|
1707
1409
|
throw new Error("no external wallet account link in progress");
|
|
1708
1410
|
}
|
|
@@ -1720,13 +1422,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1720
1422
|
* @param authResponse - the response JSON object received from the Telegram widget.
|
|
1721
1423
|
* @returns `{ isValid: boolean; telegramUserId?: string; userId?: string; isNewUser?: boolean; supportedAuthMethods?: AuthMethod[]; biometricHints?: BiometricLocationHint[] }`
|
|
1722
1424
|
*/
|
|
1723
|
-
verifyTelegramProcess(
|
|
1425
|
+
verifyTelegramProcess(_a) {
|
|
1724
1426
|
return __async(this, null, function* () {
|
|
1725
|
-
var
|
|
1427
|
+
var _b = _a, {
|
|
1726
1428
|
serverAuthState: optsServerAuthState,
|
|
1727
1429
|
telegramAuthResponse,
|
|
1728
1430
|
isLinkAccount
|
|
1729
|
-
} =
|
|
1431
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
1730
1432
|
"serverAuthState",
|
|
1731
1433
|
"telegramAuthResponse",
|
|
1732
1434
|
"isLinkAccount"
|
|
@@ -1734,12 +1436,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1734
1436
|
try {
|
|
1735
1437
|
switch (isLinkAccount) {
|
|
1736
1438
|
case false: {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
const { sessionLookupId } = yield this.touchSession();
|
|
1742
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
1439
|
+
return yield __privateGet(this, _authService).verifyTelegram(__spreadValues({
|
|
1440
|
+
serverAuthState: optsServerAuthState,
|
|
1441
|
+
telegramAuthResponse
|
|
1442
|
+
}, urlOptions));
|
|
1743
1443
|
}
|
|
1744
1444
|
case true: {
|
|
1745
1445
|
if (!telegramAuthResponse) {
|
|
@@ -1759,9 +1459,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1759
1459
|
}
|
|
1760
1460
|
});
|
|
1761
1461
|
}
|
|
1762
|
-
verifyTelegram(
|
|
1462
|
+
verifyTelegram(params) {
|
|
1763
1463
|
return __async(this, null, function* () {
|
|
1764
|
-
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({},
|
|
1464
|
+
return yield this.verifyTelegramProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
1765
1465
|
});
|
|
1766
1466
|
}
|
|
1767
1467
|
verifyTelegramLink(opts) {
|
|
@@ -1813,35 +1513,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1813
1513
|
* Resend a verification email for the current user.
|
|
1814
1514
|
*/
|
|
1815
1515
|
resendVerificationCode(_0) {
|
|
1816
|
-
return __async(this, arguments, function* ({
|
|
1817
|
-
type: reason
|
|
1818
|
-
}) {
|
|
1819
|
-
let type, linkedAccountId;
|
|
1820
|
-
switch (reason) {
|
|
1821
|
-
case "SIGNUP":
|
|
1822
|
-
case "LOGIN":
|
|
1823
|
-
{
|
|
1824
|
-
const authInfo = this.assertIsAuthSet(["email", "phone"]);
|
|
1825
|
-
type = authInfo.authType.toUpperCase();
|
|
1826
|
-
}
|
|
1827
|
-
break;
|
|
1828
|
-
case "LINK_ACCOUNT":
|
|
1829
|
-
{
|
|
1830
|
-
const accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this, ["EMAIL", "PHONE"]);
|
|
1831
|
-
linkedAccountId = accountLinkInProgress.id;
|
|
1832
|
-
type = accountLinkInProgress.type;
|
|
1833
|
-
}
|
|
1834
|
-
break;
|
|
1835
|
-
}
|
|
1836
|
-
const userId = this.assertUserId({ allowGuestMode: true });
|
|
1837
|
-
if (type !== "EMAIL" && type !== "PHONE") {
|
|
1838
|
-
throw new Error("invalid auth type for verification code");
|
|
1839
|
-
}
|
|
1840
|
-
yield this.ctx.client.resendVerificationCode(__spreadValues({
|
|
1841
|
-
userId,
|
|
1842
|
-
type,
|
|
1843
|
-
linkedAccountId
|
|
1844
|
-
}, this.getVerificationEmailProps()));
|
|
1516
|
+
return __async(this, arguments, function* ({ type: reason = "SIGNUP" }) {
|
|
1517
|
+
return yield __privateGet(this, _authService).resendVerificationCode({ type: reason });
|
|
1845
1518
|
});
|
|
1846
1519
|
}
|
|
1847
1520
|
/**
|
|
@@ -1850,18 +1523,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1850
1523
|
*/
|
|
1851
1524
|
isSessionActive() {
|
|
1852
1525
|
return __async(this, null, function* () {
|
|
1853
|
-
|
|
1854
|
-
return true;
|
|
1855
|
-
}
|
|
1856
|
-
const { isAuthenticated, verifiedExternalWalletAddresses } = yield this.touchSession();
|
|
1857
|
-
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1858
|
-
if (!verifiedExternalWalletAddresses) {
|
|
1859
|
-
return false;
|
|
1860
|
-
}
|
|
1861
|
-
const externalAddresses = Object.values(this.externalWallets).map((w) => w.id);
|
|
1862
|
-
return externalAddresses.every((address) => verifiedExternalWalletAddresses.includes(address));
|
|
1863
|
-
}
|
|
1864
|
-
return !!isAuthenticated;
|
|
1526
|
+
return yield __privateGet(this, _sessionManagementService).isSessionActive();
|
|
1865
1527
|
});
|
|
1866
1528
|
}
|
|
1867
1529
|
/**
|
|
@@ -1870,51 +1532,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1870
1532
|
**/
|
|
1871
1533
|
isFullyLoggedIn() {
|
|
1872
1534
|
return __async(this, null, function* () {
|
|
1873
|
-
|
|
1874
|
-
if (!this.isReady) {
|
|
1875
|
-
yield this.ready();
|
|
1876
|
-
}
|
|
1877
|
-
return true;
|
|
1878
|
-
}
|
|
1879
|
-
if (this.isGuestMode) {
|
|
1880
|
-
return true;
|
|
1881
|
-
}
|
|
1882
|
-
const isSessionActive = yield this.isSessionActive();
|
|
1883
|
-
if (this.externalWalletConnectionType === "VERIFICATION") {
|
|
1884
|
-
return isSessionActive;
|
|
1885
|
-
}
|
|
1886
|
-
if (this.isSwitchingWallets) {
|
|
1887
|
-
return isSessionActive;
|
|
1888
|
-
}
|
|
1889
|
-
if (!isSessionActive) {
|
|
1890
|
-
return false;
|
|
1891
|
-
}
|
|
1892
|
-
if (this.isNoWalletConfig) {
|
|
1893
|
-
return true;
|
|
1894
|
-
}
|
|
1895
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
1896
|
-
const requiredWalletTypes = supportedWalletTypes.filter(({ optional }) => !optional);
|
|
1897
|
-
for (const { type } of requiredWalletTypes) {
|
|
1898
|
-
const hasWalletForType = this.currentWalletIdsArray.some(([walletId, walletType]) => {
|
|
1899
|
-
try {
|
|
1900
|
-
const wallet = this.wallets[walletId];
|
|
1901
|
-
return wallet && walletType === type && typeof wallet.address === "string";
|
|
1902
|
-
} catch (e) {
|
|
1903
|
-
return false;
|
|
1904
|
-
}
|
|
1905
|
-
});
|
|
1906
|
-
if (!hasWalletForType) {
|
|
1907
|
-
return false;
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
return true;
|
|
1535
|
+
return yield __privateGet(this, _sessionManagementService).isFullyLoggedIn();
|
|
1911
1536
|
});
|
|
1912
1537
|
}
|
|
1913
1538
|
get isGuestMode() {
|
|
1914
|
-
|
|
1539
|
+
var _a;
|
|
1540
|
+
return ((_a = __privateGet(this, _pregenWalletService)) == null ? void 0 : _a.guestWalletIdsArray.length) > 0 && Object.values(this.wallets).every(
|
|
1915
1541
|
({ userId, partnerId }) => {
|
|
1916
|
-
var
|
|
1917
|
-
return partnerId === ((
|
|
1542
|
+
var _a2;
|
|
1543
|
+
return partnerId === ((_a2 = this.partner) == null ? void 0 : _a2.id) && (!userId || userId !== this.userId);
|
|
1918
1544
|
}
|
|
1919
1545
|
);
|
|
1920
1546
|
}
|
|
@@ -1944,30 +1570,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1944
1570
|
*/
|
|
1945
1571
|
supportedUserAuthMethods() {
|
|
1946
1572
|
return __async(this, null, function* () {
|
|
1947
|
-
yield this.
|
|
1948
|
-
const { supportedAuthMethods, hasPasswordWithoutPIN } = yield this.ctx.client.getSupportedAuthMethodsV2(
|
|
1949
|
-
this.authInfo.auth
|
|
1950
|
-
);
|
|
1951
|
-
const authMethods = /* @__PURE__ */ new Set();
|
|
1952
|
-
for (const type of supportedAuthMethods) {
|
|
1953
|
-
switch (type) {
|
|
1954
|
-
case "PASSWORD":
|
|
1955
|
-
if (hasPasswordWithoutPIN) {
|
|
1956
|
-
authMethods.add(AuthMethod.PASSWORD);
|
|
1957
|
-
}
|
|
1958
|
-
break;
|
|
1959
|
-
case "PASSKEY":
|
|
1960
|
-
authMethods.add(AuthMethod.PASSKEY);
|
|
1961
|
-
break;
|
|
1962
|
-
case "PIN":
|
|
1963
|
-
authMethods.add(AuthMethod.PIN);
|
|
1964
|
-
break;
|
|
1965
|
-
case "BASIC_LOGIN":
|
|
1966
|
-
authMethods.add(AuthMethod.BASIC_LOGIN);
|
|
1967
|
-
break;
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
return authMethods;
|
|
1573
|
+
return yield __privateGet(this, _authService).supportedUserAuthMethods();
|
|
1971
1574
|
});
|
|
1972
1575
|
}
|
|
1973
1576
|
/**
|
|
@@ -1984,94 +1587,14 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
1984
1587
|
/**
|
|
1985
1588
|
* Waits for the session to be active.
|
|
1986
1589
|
**/
|
|
1987
|
-
waitForSignup(
|
|
1988
|
-
return __async(this,
|
|
1989
|
-
|
|
1990
|
-
onCancel,
|
|
1991
|
-
onPoll
|
|
1992
|
-
}) {
|
|
1993
|
-
const startedAt = Date.now();
|
|
1994
|
-
return new Promise((resolve, reject) => {
|
|
1995
|
-
(() => __async(this, null, function* () {
|
|
1996
|
-
yield this.touchSession();
|
|
1997
|
-
if (!this.isExternalWalletAuth) {
|
|
1998
|
-
this.externalWallets = {};
|
|
1999
|
-
}
|
|
2000
|
-
while (true) {
|
|
2001
|
-
try {
|
|
2002
|
-
if (isCanceled() || Date.now() - startedAt > constants.POLLING_TIMEOUT_MS) {
|
|
2003
|
-
onCancel == null ? void 0 : onCancel();
|
|
2004
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, false, "failed to sign up user");
|
|
2005
|
-
return reject("canceled");
|
|
2006
|
-
}
|
|
2007
|
-
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2008
|
-
if (yield this.isSessionActive()) {
|
|
2009
|
-
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
2010
|
-
return resolve(true);
|
|
2011
|
-
}
|
|
2012
|
-
onPoll == null ? void 0 : onPoll();
|
|
2013
|
-
} catch (err) {
|
|
2014
|
-
console.error(err);
|
|
2015
|
-
onPoll == null ? void 0 : onPoll();
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
}))();
|
|
2019
|
-
});
|
|
1590
|
+
waitForSignup(params) {
|
|
1591
|
+
return __async(this, null, function* () {
|
|
1592
|
+
return yield __privateGet(this, _authService).waitForSignup(params);
|
|
2020
1593
|
});
|
|
2021
1594
|
}
|
|
2022
|
-
waitForWalletCreation() {
|
|
2023
|
-
return __async(this,
|
|
2024
|
-
|
|
2025
|
-
onCancel
|
|
2026
|
-
} = {}) {
|
|
2027
|
-
yield this.waitForSignup({ isCanceled, onCancel });
|
|
2028
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2029
|
-
const pregenWallets = yield this.getPregenWallets();
|
|
2030
|
-
let recoverySecret, walletIds = {};
|
|
2031
|
-
if (pregenWallets.length > 0) {
|
|
2032
|
-
let shares = [];
|
|
2033
|
-
try {
|
|
2034
|
-
shares = yield this.ctx.enclaveClient.getPregenShares({
|
|
2035
|
-
userId: this.userId,
|
|
2036
|
-
walletIds: pregenWallets.map((w) => w.id),
|
|
2037
|
-
partnerId: pregenWallets[0].partnerId
|
|
2038
|
-
});
|
|
2039
|
-
for (const share of shares) {
|
|
2040
|
-
const wallet = pregenWallets.find((w) => w.id === share.walletId);
|
|
2041
|
-
if (wallet) {
|
|
2042
|
-
this.wallets[wallet.id] = {
|
|
2043
|
-
id: wallet.id,
|
|
2044
|
-
address: wallet.address,
|
|
2045
|
-
scheme: wallet.scheme,
|
|
2046
|
-
type: wallet.type,
|
|
2047
|
-
partnerId: wallet.partnerId,
|
|
2048
|
-
isPregen: wallet.isPregen,
|
|
2049
|
-
pregenIdentifier: wallet.pregenIdentifier,
|
|
2050
|
-
pregenIdentifierType: wallet.pregenIdentifierType,
|
|
2051
|
-
signer: share.signer,
|
|
2052
|
-
createdAt: String(wallet.createdAt)
|
|
2053
|
-
};
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
} catch (err) {
|
|
2057
|
-
console.warn("[waitForWalletCreation] Failed to fetch pregen shares:", err);
|
|
2058
|
-
}
|
|
2059
|
-
if (shares.length > 0) {
|
|
2060
|
-
recoverySecret = yield this.claimPregenWallets();
|
|
2061
|
-
walletIds = supportedWalletTypes.reduce((acc, { type }) => {
|
|
2062
|
-
var _a;
|
|
2063
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
2064
|
-
[type]: [(_a = pregenWallets.find((w) => !!WalletSchemeTypeMap[w.scheme][type])) == null ? void 0 : _a.id]
|
|
2065
|
-
});
|
|
2066
|
-
}, {});
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
const created = yield this.createWalletPerType();
|
|
2070
|
-
recoverySecret = recoverySecret != null ? recoverySecret : created.recoverySecret;
|
|
2071
|
-
walletIds = __spreadValues(__spreadValues({}, walletIds), created.walletIds);
|
|
2072
|
-
const resp = { walletIds, recoverySecret };
|
|
2073
|
-
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
2074
|
-
return resp;
|
|
1595
|
+
waitForWalletCreation(params) {
|
|
1596
|
+
return __async(this, null, function* () {
|
|
1597
|
+
return yield __privateGet(this, _authService).waitForWalletCreation(params);
|
|
2075
1598
|
});
|
|
2076
1599
|
}
|
|
2077
1600
|
/**
|
|
@@ -2091,35 +1614,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2091
1614
|
* If successful, this returns the user's Farcaster username and profile picture and indicates whether the user already exists.
|
|
2092
1615
|
* @return {Object} `{userExists: boolean; username: string; pfpUrl?: string | null }` - the user's information and whether the user already exists.
|
|
2093
1616
|
*/
|
|
2094
|
-
verifyFarcasterProcess(
|
|
1617
|
+
verifyFarcasterProcess(_c) {
|
|
2095
1618
|
return __async(this, null, function* () {
|
|
2096
|
-
var
|
|
1619
|
+
var _d = _c, {
|
|
2097
1620
|
isCanceled = () => false,
|
|
2098
1621
|
onConnectUri,
|
|
2099
1622
|
onCancel,
|
|
2100
|
-
onPoll,
|
|
2101
1623
|
isLinkAccount,
|
|
2102
1624
|
serverAuthState: optsServerAuthState
|
|
2103
|
-
} =
|
|
1625
|
+
} = _d, urlOptions = __objRest(_d, [
|
|
2104
1626
|
"isCanceled",
|
|
2105
1627
|
"onConnectUri",
|
|
2106
1628
|
"onCancel",
|
|
2107
|
-
"onPoll",
|
|
2108
1629
|
"isLinkAccount",
|
|
2109
1630
|
"serverAuthState"
|
|
2110
1631
|
]);
|
|
2111
|
-
if (
|
|
2112
|
-
const
|
|
2113
|
-
|
|
1632
|
+
if (onConnectUri) {
|
|
1633
|
+
const connectUri = yield this.getFarcasterConnectUri();
|
|
1634
|
+
onConnectUri(connectUri);
|
|
1635
|
+
}
|
|
1636
|
+
if (!isLinkAccount) {
|
|
1637
|
+
return yield __privateGet(this, _authService).verifyFarcaster(__spreadValues({
|
|
1638
|
+
serverAuthState: optsServerAuthState
|
|
1639
|
+
}, urlOptions));
|
|
2114
1640
|
}
|
|
2115
1641
|
let accountLinkInProgress;
|
|
2116
1642
|
if (isLinkAccount) {
|
|
2117
1643
|
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, "FARCASTER");
|
|
2118
1644
|
}
|
|
2119
|
-
if (onConnectUri) {
|
|
2120
|
-
const connectUri = yield this.getFarcasterConnectUri();
|
|
2121
|
-
onConnectUri(connectUri);
|
|
2122
|
-
}
|
|
2123
1645
|
return new Promise((resolve, reject) => {
|
|
2124
1646
|
(() => __async(this, null, function* () {
|
|
2125
1647
|
const startedAt = Date.now();
|
|
@@ -2130,27 +1652,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2130
1652
|
return reject("CANCELED");
|
|
2131
1653
|
}
|
|
2132
1654
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2139
|
-
return resolve(authState);
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
break;
|
|
2143
|
-
case true: {
|
|
2144
|
-
const result = yield this.verifyLink({
|
|
2145
|
-
accountLinkInProgress
|
|
2146
|
-
});
|
|
2147
|
-
if ("isConflict" in result) {
|
|
2148
|
-
throw new Error(AccountLinkError.Conflict);
|
|
2149
|
-
}
|
|
2150
|
-
return resolve(result);
|
|
2151
|
-
}
|
|
1655
|
+
const result = yield this.verifyLink({
|
|
1656
|
+
accountLinkInProgress
|
|
1657
|
+
});
|
|
1658
|
+
if ("isConflict" in result) {
|
|
1659
|
+
throw new Error(AccountLinkError.Conflict);
|
|
2152
1660
|
}
|
|
2153
|
-
|
|
1661
|
+
return resolve(result);
|
|
2154
1662
|
} catch (e) {
|
|
2155
1663
|
if (!isLinkAccount || e.message === AccountLinkError.Conflict) {
|
|
2156
1664
|
return reject(e.message);
|
|
@@ -2161,9 +1669,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2161
1669
|
});
|
|
2162
1670
|
});
|
|
2163
1671
|
}
|
|
2164
|
-
verifyFarcaster(
|
|
1672
|
+
verifyFarcaster(params) {
|
|
2165
1673
|
return __async(this, null, function* () {
|
|
2166
|
-
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({},
|
|
1674
|
+
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
2167
1675
|
});
|
|
2168
1676
|
}
|
|
2169
1677
|
verifyFarcasterLink(opts) {
|
|
@@ -2171,11 +1679,17 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2171
1679
|
return yield this.verifyFarcasterProcess(__spreadProps(__spreadValues({}, opts), { isLinkAccount: true }));
|
|
2172
1680
|
});
|
|
2173
1681
|
}
|
|
2174
|
-
|
|
1682
|
+
/**
|
|
1683
|
+
* Generates a URL for the user to log in with OAuth using a desire method.
|
|
1684
|
+
*
|
|
1685
|
+
* @param {Object} opts the options object
|
|
1686
|
+
* @param {TOAuthMethod} opts.method the third-party service to use for OAuth.
|
|
1687
|
+
* @param {string} [opts.appScheme] the app scheme to redirect to after the OAuth flow. This is for mobile only.
|
|
1688
|
+
* @returns {string} the URL for the user to log in with OAuth.
|
|
1689
|
+
*/
|
|
1690
|
+
getOAuthUrl(params) {
|
|
2175
1691
|
return __async(this, null, function* () {
|
|
2176
|
-
|
|
2177
|
-
const sessionLookupId = (_a = opts.sessionLookupId) != null ? _a : yield this.prepareLogin();
|
|
2178
|
-
return __privateMethod(this, _ParaCore_instances, getOAuthUrl_fn).call(this, __spreadProps(__spreadValues({}, opts), { sessionLookupId }));
|
|
1692
|
+
return yield __privateGet(this, _portalUrlService).getOAuthUrl(params);
|
|
2179
1693
|
});
|
|
2180
1694
|
}
|
|
2181
1695
|
/**
|
|
@@ -2186,27 +1700,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2186
1700
|
* @param {Window} [opts.popupWindow] the popup window being used for login.
|
|
2187
1701
|
* @return {Object} `{ email?: string; isError?: boolean; userExists: boolean; }` the result data
|
|
2188
1702
|
*/
|
|
2189
|
-
verifyOAuthProcess(
|
|
1703
|
+
verifyOAuthProcess(params) {
|
|
2190
1704
|
return __async(this, null, function* () {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
onCancel,
|
|
2196
|
-
onPoll,
|
|
2197
|
-
onOAuthUrl,
|
|
2198
|
-
onOAuthPopup,
|
|
2199
|
-
isLinkAccount
|
|
2200
|
-
} = _h, urlOptions = __objRest(_h, [
|
|
2201
|
-
"method",
|
|
2202
|
-
"appScheme",
|
|
2203
|
-
"isCanceled",
|
|
2204
|
-
"onCancel",
|
|
2205
|
-
"onPoll",
|
|
2206
|
-
"onOAuthUrl",
|
|
2207
|
-
"onOAuthPopup",
|
|
2208
|
-
"isLinkAccount"
|
|
2209
|
-
]);
|
|
1705
|
+
if (!params.isLinkAccount) {
|
|
1706
|
+
return yield __privateGet(this, _authService).verifyOAuthProcess(params);
|
|
1707
|
+
}
|
|
1708
|
+
const { method, appScheme, isCanceled = () => false, onCancel, onPoll, onOAuthUrl, onOAuthPopup } = params;
|
|
2210
1709
|
if (onOAuthPopup) {
|
|
2211
1710
|
try {
|
|
2212
1711
|
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.OAUTH });
|
|
@@ -2216,13 +1715,14 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2216
1715
|
}
|
|
2217
1716
|
let sessionLookupId, accountLinkInProgress;
|
|
2218
1717
|
if (onOAuthUrl || onOAuthPopup) {
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
1718
|
+
accountLinkInProgress = yield __privateMethod(this, _ParaCore_instances, assertIsLinkingAccountOrStart_fn).call(this, method);
|
|
1719
|
+
sessionLookupId = (yield this.touchSession()).sessionLookupId;
|
|
1720
|
+
const oAuthUrl = yield __privateGet(this, _portalUrlService).getOAuthUrl({
|
|
1721
|
+
method,
|
|
1722
|
+
appScheme,
|
|
1723
|
+
sessionLookupId,
|
|
1724
|
+
accountLinkInProgress
|
|
1725
|
+
});
|
|
2226
1726
|
switch (true) {
|
|
2227
1727
|
case !!onOAuthUrl: {
|
|
2228
1728
|
onOAuthUrl(oAuthUrl);
|
|
@@ -2247,24 +1747,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2247
1747
|
return reject(AccountLinkError.Canceled);
|
|
2248
1748
|
}
|
|
2249
1749
|
yield new Promise((_resolve) => setTimeout(_resolve, constants.POLLING_INTERVAL_MS));
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
{
|
|
2253
|
-
const serverAuthState = yield this.ctx.client.verifyOAuth();
|
|
2254
|
-
if (isServerAuthState(serverAuthState)) {
|
|
2255
|
-
const authState = yield __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, urlOptions), { sessionLookupId }));
|
|
2256
|
-
return resolve(authState);
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
break;
|
|
2260
|
-
case true: {
|
|
2261
|
-
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
2262
|
-
return resolve(accounts);
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
onPoll == null ? void 0 : onPoll();
|
|
1750
|
+
const accounts = yield this.verifyLink({ accountLinkInProgress });
|
|
1751
|
+
return resolve(accounts);
|
|
2266
1752
|
} catch (err) {
|
|
2267
|
-
if (
|
|
1753
|
+
if (err.message === AccountLinkError.Conflict) {
|
|
2268
1754
|
return reject(err.message);
|
|
2269
1755
|
}
|
|
2270
1756
|
onPoll == null ? void 0 : onPoll();
|
|
@@ -2274,9 +1760,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2274
1760
|
});
|
|
2275
1761
|
});
|
|
2276
1762
|
}
|
|
2277
|
-
verifyOAuth(
|
|
1763
|
+
verifyOAuth(params) {
|
|
2278
1764
|
return __async(this, null, function* () {
|
|
2279
|
-
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({},
|
|
1765
|
+
return yield this.verifyOAuthProcess(__spreadProps(__spreadValues({}, params), { isLinkAccount: false }));
|
|
2280
1766
|
});
|
|
2281
1767
|
}
|
|
2282
1768
|
verifyOAuthLink(opts) {
|
|
@@ -2292,9 +1778,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2292
1778
|
* @param {boolean} [opts.skipSessionRefresh] whether to skip refreshing the session.
|
|
2293
1779
|
* @returns {Object} `{ isComplete: boolean; isError: boolean; needsWallet: boolean; partnerId: string; }` the result data
|
|
2294
1780
|
**/
|
|
2295
|
-
waitForLogin(
|
|
1781
|
+
waitForLogin(params) {
|
|
2296
1782
|
return __async(this, null, function* () {
|
|
2297
|
-
return yield
|
|
1783
|
+
return yield __privateGet(this, _authService).waitForLogin(params);
|
|
2298
1784
|
});
|
|
2299
1785
|
}
|
|
2300
1786
|
waitForWalletSwitching(args) {
|
|
@@ -2310,7 +1796,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2310
1796
|
*/
|
|
2311
1797
|
getSwitchWalletsUrl() {
|
|
2312
1798
|
return __async(this, null, function* () {
|
|
2313
|
-
const
|
|
1799
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
1800
|
+
const url = yield this.constructPortalUrl("switchWallets", {
|
|
1801
|
+
useLegacyUrl: authMethods.has(AuthMethod.PASSKEY)
|
|
1802
|
+
});
|
|
2314
1803
|
return url;
|
|
2315
1804
|
});
|
|
2316
1805
|
}
|
|
@@ -2323,32 +1812,20 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2323
1812
|
* @returns a URL for the user to reauthenticate.
|
|
2324
1813
|
**/
|
|
2325
1814
|
refreshSession() {
|
|
2326
|
-
return __async(this, arguments, function* ({
|
|
2327
|
-
|
|
2328
|
-
} = {}) {
|
|
2329
|
-
const { sessionId } = yield this.touchSession(true);
|
|
2330
|
-
if (!this.loginEncryptionKeyPair) {
|
|
2331
|
-
yield this.setLoginEncryptionKeyPair();
|
|
2332
|
-
}
|
|
2333
|
-
const link = yield this.getLoginUrl({
|
|
2334
|
-
sessionId
|
|
2335
|
-
});
|
|
2336
|
-
if (shouldOpenPopup) {
|
|
2337
|
-
yield this.platformUtils.openPopup(link);
|
|
2338
|
-
}
|
|
2339
|
-
return link;
|
|
1815
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1816
|
+
return yield __privateGet(this, _sessionManagementService).refreshSession(params);
|
|
2340
1817
|
});
|
|
2341
1818
|
}
|
|
2342
1819
|
/**
|
|
2343
1820
|
* Call this method after login to ensure that the user ID is set
|
|
2344
1821
|
* internally.
|
|
2345
1822
|
**/
|
|
2346
|
-
userSetupAfterLogin() {
|
|
1823
|
+
userSetupAfterLogin(existingSession) {
|
|
2347
1824
|
return __async(this, null, function* () {
|
|
2348
|
-
const session = yield this.touchSession();
|
|
2349
|
-
yield this.setUserId(session.userId);
|
|
2350
|
-
if (session.currentWalletIds && session.currentWalletIds !== this.currentWalletIds)
|
|
2351
|
-
yield this.setCurrentWalletIds(session.currentWalletIds, {
|
|
1825
|
+
const session = existingSession != null ? existingSession : yield this.touchSession();
|
|
1826
|
+
yield __privateGet(this, _authService).setUserId(session.userId);
|
|
1827
|
+
if (session.currentWalletIds && session.currentWalletIds !== __privateGet(this, _walletService).currentWalletIds)
|
|
1828
|
+
yield __privateGet(this, _walletService).setCurrentWalletIds(session.currentWalletIds, {
|
|
2352
1829
|
sessionLookupId: this.isPortal() ? session.sessionLookupId : void 0
|
|
2353
1830
|
});
|
|
2354
1831
|
return session;
|
|
@@ -2361,9 +1838,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2361
1838
|
* @returns - transmission keyshares.
|
|
2362
1839
|
**/
|
|
2363
1840
|
getTransmissionKeyShares() {
|
|
2364
|
-
return __async(this, arguments, function* ({
|
|
2365
|
-
|
|
2366
|
-
|
|
1841
|
+
return __async(this, arguments, function* ({
|
|
1842
|
+
isForNewDevice = false,
|
|
1843
|
+
sessionLookupId: existingSessionLookupId
|
|
1844
|
+
} = {}) {
|
|
1845
|
+
const baseSessionLookupId = existingSessionLookupId != null ? existingSessionLookupId : (yield this.touchSession()).sessionLookupId;
|
|
1846
|
+
const sessionLookupId = isForNewDevice ? `${baseSessionLookupId}-new-device` : baseSessionLookupId;
|
|
2367
1847
|
return this.ctx.client.getTransmissionKeyshares(this.userId, sessionLookupId);
|
|
2368
1848
|
});
|
|
2369
1849
|
}
|
|
@@ -2377,111 +1857,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2377
1857
|
return __async(this, arguments, function* ({
|
|
2378
1858
|
temporaryShares,
|
|
2379
1859
|
skipSessionRefresh = false
|
|
2380
|
-
} = {}) {
|
|
2381
|
-
if (!temporaryShares) {
|
|
2382
|
-
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2383
|
-
}
|
|
2384
|
-
temporaryShares.forEach((share) => {
|
|
2385
|
-
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
2386
|
-
this.wallets[share.walletId] = {
|
|
2387
|
-
id: share.walletId,
|
|
2388
|
-
signer
|
|
2389
|
-
};
|
|
2390
|
-
});
|
|
2391
|
-
yield this.deleteLoginEncryptionKeyPair();
|
|
2392
|
-
yield this.populateWalletAddresses();
|
|
2393
|
-
yield this.touchSession(!skipSessionRefresh);
|
|
2394
|
-
});
|
|
2395
|
-
}
|
|
2396
|
-
/**
|
|
2397
|
-
* Distributes a new wallet recovery share.
|
|
2398
|
-
* @param {Object} opts the options object.
|
|
2399
|
-
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
2400
|
-
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
2401
|
-
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
2402
|
-
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
2403
|
-
* @returns {string} the recovery share.
|
|
2404
|
-
**/
|
|
2405
|
-
distributeNewWalletShare(_0) {
|
|
2406
|
-
return __async(this, arguments, function* ({
|
|
2407
|
-
walletId,
|
|
2408
|
-
userShare,
|
|
2409
|
-
skipBiometricShareCreation = false,
|
|
2410
|
-
forceRefresh = false
|
|
2411
|
-
}) {
|
|
2412
|
-
let userSigner = userShare;
|
|
2413
|
-
if (!userSigner) {
|
|
2414
|
-
userSigner = this.wallets[walletId].signer;
|
|
2415
|
-
}
|
|
2416
|
-
const recoveryShare = skipBiometricShareCreation ? yield sendRecoveryForShare({
|
|
2417
|
-
ctx: this.ctx,
|
|
2418
|
-
userId: this.userId,
|
|
2419
|
-
walletId,
|
|
2420
|
-
userSigner,
|
|
2421
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2422
|
-
forceRefresh
|
|
2423
|
-
}) : yield distributeNewShare({
|
|
2424
|
-
ctx: this.ctx,
|
|
2425
|
-
userId: this.userId,
|
|
2426
|
-
walletId,
|
|
2427
|
-
userShare: userSigner,
|
|
2428
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2429
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2430
|
-
walletScheme: this.wallets[walletId].scheme
|
|
2431
|
-
});
|
|
2432
|
-
return recoveryShare;
|
|
2433
|
-
});
|
|
2434
|
-
}
|
|
2435
|
-
waitForWalletAddress(walletId) {
|
|
2436
|
-
return __async(this, null, function* () {
|
|
2437
|
-
let maxPolls = 0;
|
|
2438
|
-
while (true) {
|
|
2439
|
-
try {
|
|
2440
|
-
if (maxPolls === 10) {
|
|
2441
|
-
break;
|
|
2442
|
-
}
|
|
2443
|
-
++maxPolls;
|
|
2444
|
-
const res = yield (this.isPortal() ? this.ctx.client.getAllWallets : this.ctx.client.getWallets)(this.userId);
|
|
2445
|
-
const wallet = res.data.wallets.find((w) => w.id === walletId);
|
|
2446
|
-
if (wallet && wallet.address) {
|
|
2447
|
-
return;
|
|
2448
|
-
}
|
|
2449
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
2450
|
-
} catch (err) {
|
|
2451
|
-
console.error(err);
|
|
2452
|
-
}
|
|
1860
|
+
} = {}) {
|
|
1861
|
+
if (!temporaryShares) {
|
|
1862
|
+
temporaryShares = (yield this.getTransmissionKeyShares()).data.temporaryShares;
|
|
2453
1863
|
}
|
|
2454
|
-
|
|
1864
|
+
temporaryShares.forEach((share) => {
|
|
1865
|
+
const signer = decryptWithPrivateKey(this.loginEncryptionKeyPair.privateKey, share.encryptedShare, share.encryptedKey);
|
|
1866
|
+
this.wallets[share.walletId] = {
|
|
1867
|
+
id: share.walletId,
|
|
1868
|
+
signer
|
|
1869
|
+
};
|
|
1870
|
+
});
|
|
1871
|
+
yield this.deleteLoginEncryptionKeyPair();
|
|
1872
|
+
yield __privateGet(this, _walletService).populateWalletAddresses();
|
|
1873
|
+
yield this.touchSession(!skipSessionRefresh);
|
|
2455
1874
|
});
|
|
2456
1875
|
}
|
|
2457
1876
|
/**
|
|
2458
|
-
*
|
|
2459
|
-
*
|
|
2460
|
-
* @param
|
|
2461
|
-
* @param
|
|
2462
|
-
* @param
|
|
2463
|
-
* @
|
|
1877
|
+
* Distributes a new wallet recovery share.
|
|
1878
|
+
* @param {Object} opts the options object.
|
|
1879
|
+
* @param {string} opts.walletId the wallet to distribute the recovery share for.
|
|
1880
|
+
* @param {string} opts.userShare optional user share generate the recovery share from. Defaults to the signer from the passed in walletId
|
|
1881
|
+
* @param {boolean} opts.skipBiometricShareCreation whether or not to skip biometric share creation. Used when regenerating recovery shares.
|
|
1882
|
+
* @param {boolean} opts.forceRefreshRecovery whether or not to force recovery secret regeneration. Used when regenerating recovery shares.
|
|
1883
|
+
* @returns {string} the recovery share.
|
|
2464
1884
|
**/
|
|
2465
|
-
|
|
1885
|
+
distributeNewWalletShare(params) {
|
|
2466
1886
|
return __async(this, null, function* () {
|
|
2467
|
-
|
|
2468
|
-
while (true) {
|
|
2469
|
-
try {
|
|
2470
|
-
if (maxPolls === 10) {
|
|
2471
|
-
break;
|
|
2472
|
-
}
|
|
2473
|
-
++maxPolls;
|
|
2474
|
-
const res = yield this.getPregenWallets();
|
|
2475
|
-
const wallet = res.find((w) => w.id === walletId);
|
|
2476
|
-
if (wallet && wallet.address) {
|
|
2477
|
-
return;
|
|
2478
|
-
}
|
|
2479
|
-
yield new Promise((resolve) => setTimeout(resolve, constants.SHORT_POLLING_INTERVAL_MS));
|
|
2480
|
-
} catch (err) {
|
|
2481
|
-
console.error(err);
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
throw new Error("timed out waiting for wallet address");
|
|
1887
|
+
return yield __privateGet(this, _walletService).distributeNewWalletShare(params);
|
|
2485
1888
|
});
|
|
2486
1889
|
}
|
|
2487
1890
|
/**
|
|
@@ -2496,24 +1899,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2496
1899
|
* @returns {Object} the wallets created, their ids, and the recovery secret.
|
|
2497
1900
|
**/
|
|
2498
1901
|
createWalletPerType() {
|
|
2499
|
-
return __async(this, arguments, function* ({
|
|
2500
|
-
|
|
2501
|
-
types
|
|
2502
|
-
} = {}) {
|
|
2503
|
-
const wallets = [];
|
|
2504
|
-
const walletIds = {};
|
|
2505
|
-
let recoverySecret;
|
|
2506
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2507
|
-
const [wallet, recoveryShare] = yield this.createWallet({ type, skipDistribute });
|
|
2508
|
-
wallets.push(wallet);
|
|
2509
|
-
getEquivalentTypes(type).filter((t) => !!this.isWalletTypeEnabled[t]).forEach((t) => {
|
|
2510
|
-
walletIds[t] = [wallet.id];
|
|
2511
|
-
});
|
|
2512
|
-
if (recoveryShare) {
|
|
2513
|
-
recoverySecret = recoveryShare;
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
return { wallets, walletIds, recoverySecret };
|
|
1902
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1903
|
+
return yield __privateGet(this, _walletService).createWalletPerType(params);
|
|
2517
1904
|
});
|
|
2518
1905
|
}
|
|
2519
1906
|
/**
|
|
@@ -2528,38 +1915,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2528
1915
|
* @param {boolean} [opts.redistributeBackupEncryptedShares] whether or not to redistribute backup encrypted shares.
|
|
2529
1916
|
* @returns {Object} the new user share and recovery secret.
|
|
2530
1917
|
**/
|
|
2531
|
-
refreshShare(
|
|
2532
|
-
return __async(this,
|
|
2533
|
-
|
|
2534
|
-
share,
|
|
2535
|
-
oldPartnerId,
|
|
2536
|
-
newPartnerId,
|
|
2537
|
-
keyShareProtocolId,
|
|
2538
|
-
redistributeBackupEncryptedShares
|
|
2539
|
-
}) {
|
|
2540
|
-
const { signer, protocolId } = yield this.platformUtils.refresh(
|
|
2541
|
-
this.ctx,
|
|
2542
|
-
this.retrieveSessionCookie(),
|
|
2543
|
-
this.userId,
|
|
2544
|
-
walletId,
|
|
2545
|
-
share,
|
|
2546
|
-
oldPartnerId,
|
|
2547
|
-
newPartnerId,
|
|
2548
|
-
keyShareProtocolId
|
|
2549
|
-
);
|
|
2550
|
-
const recoverySecret = yield distributeNewShare({
|
|
2551
|
-
ctx: this.ctx,
|
|
2552
|
-
userId: this.userId,
|
|
2553
|
-
walletId,
|
|
2554
|
-
userShare: signer,
|
|
2555
|
-
ignoreRedistributingBackupEncryptedShare: !redistributeBackupEncryptedShares,
|
|
2556
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2557
|
-
partnerId: newPartnerId,
|
|
2558
|
-
protocolId,
|
|
2559
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2560
|
-
walletScheme: this.wallets[walletId].scheme
|
|
2561
|
-
});
|
|
2562
|
-
return { signer, recoverySecret, protocolId };
|
|
1918
|
+
refreshShare(params) {
|
|
1919
|
+
return __async(this, null, function* () {
|
|
1920
|
+
return yield __privateGet(this, _walletService).refreshShare(params);
|
|
2563
1921
|
});
|
|
2564
1922
|
}
|
|
2565
1923
|
/**
|
|
@@ -2570,80 +1928,22 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2570
1928
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2571
1929
|
**/
|
|
2572
1930
|
createWallet() {
|
|
2573
|
-
return __async(this, arguments, function* ({
|
|
2574
|
-
|
|
2575
|
-
skipDistribute = false
|
|
2576
|
-
} = {}) {
|
|
2577
|
-
var _a, _b;
|
|
2578
|
-
this.requireApiKey();
|
|
2579
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2580
|
-
const walletType = yield this.assertIsValidWalletType(
|
|
2581
|
-
_type != null ? _type : (_a = supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type
|
|
2582
|
-
);
|
|
2583
|
-
let signer;
|
|
2584
|
-
let wallet;
|
|
2585
|
-
let keygenRes;
|
|
2586
|
-
switch (walletType) {
|
|
2587
|
-
case "SOLANA": {
|
|
2588
|
-
keygenRes = yield this.platformUtils.ed25519Keygen(
|
|
2589
|
-
this.ctx,
|
|
2590
|
-
this.userId,
|
|
2591
|
-
this.retrieveSessionCookie(),
|
|
2592
|
-
this.getBackupKitEmailProps()
|
|
2593
|
-
);
|
|
2594
|
-
break;
|
|
2595
|
-
}
|
|
2596
|
-
default: {
|
|
2597
|
-
keygenRes = yield this.platformUtils.keygen(
|
|
2598
|
-
this.ctx,
|
|
2599
|
-
this.userId,
|
|
2600
|
-
walletType,
|
|
2601
|
-
null,
|
|
2602
|
-
this.retrieveSessionCookie(),
|
|
2603
|
-
this.getBackupKitEmailProps()
|
|
2604
|
-
);
|
|
2605
|
-
break;
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
const walletId = keygenRes.walletId;
|
|
2609
|
-
const walletScheme = walletType === "SOLANA" ? "ED25519" : "DKLS";
|
|
2610
|
-
signer = keygenRes.signer;
|
|
2611
|
-
yield this.waitForWalletAddress(walletId);
|
|
2612
|
-
let recoveryShare = null;
|
|
2613
|
-
if (!skipDistribute) {
|
|
2614
|
-
recoveryShare = yield distributeNewShare({
|
|
2615
|
-
ctx: this.ctx,
|
|
2616
|
-
userId: this.userId,
|
|
2617
|
-
walletId,
|
|
2618
|
-
userShare: signer,
|
|
2619
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2620
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2621
|
-
walletScheme
|
|
2622
|
-
});
|
|
2623
|
-
}
|
|
2624
|
-
this.wallets[walletId] = {
|
|
2625
|
-
id: walletId,
|
|
2626
|
-
signer,
|
|
2627
|
-
scheme: walletScheme,
|
|
2628
|
-
type: walletType
|
|
2629
|
-
};
|
|
2630
|
-
wallet = this.wallets[walletId];
|
|
2631
|
-
yield this.populateWalletAddresses();
|
|
2632
|
-
yield this.setCurrentWalletIds(__spreadProps(__spreadValues({}, this.currentWalletIds), {
|
|
2633
|
-
[walletType]: [.../* @__PURE__ */ new Set([...(_b = this.currentWalletIds[walletType]) != null ? _b : [], walletId])]
|
|
2634
|
-
}));
|
|
2635
|
-
const walletNoSigner = __spreadValues({}, wallet);
|
|
2636
|
-
delete walletNoSigner.signer;
|
|
2637
|
-
dispatchEvent(ParaEvent.WALLET_CREATED, {
|
|
2638
|
-
wallet: walletNoSigner,
|
|
2639
|
-
recoverySecret: recoveryShare
|
|
2640
|
-
});
|
|
2641
|
-
return [wallet, recoveryShare];
|
|
1931
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1932
|
+
return yield __privateGet(this, _walletService).createWallet(params);
|
|
2642
1933
|
});
|
|
2643
1934
|
}
|
|
2644
|
-
|
|
1935
|
+
/**
|
|
1936
|
+
* Creates a new pregenerated wallet.
|
|
1937
|
+
*
|
|
1938
|
+
* @param {Object} opts the options object.
|
|
1939
|
+
* @param {string} opts.pregenIdentifier the identifier associated with the new wallet.
|
|
1940
|
+
* @param {TPregenIdentifierType} [opts.pregenIdentifierType] the identifier type. Defaults to `EMAIL`.
|
|
1941
|
+
* @param {TWalletType} [opts.type] the type of wallet to create. Defaults to the first non-optional type in the instance's `supportedWalletTypes` array.
|
|
1942
|
+
* @returns {Wallet} the created wallet.
|
|
1943
|
+
**/
|
|
1944
|
+
createPregenWallet(params) {
|
|
2645
1945
|
return __async(this, null, function* () {
|
|
2646
|
-
return yield
|
|
1946
|
+
return yield __privateGet(this, _pregenWalletService).createPregenWallet(params);
|
|
2647
1947
|
});
|
|
2648
1948
|
}
|
|
2649
1949
|
/**
|
|
@@ -2656,17 +1956,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2656
1956
|
* @param {TWalletType[]} [opts.types] the wallet types to create. Defaults to any types the instance supports that are not already present.
|
|
2657
1957
|
* @returns {Wallet[]} an array containing the created wallets.
|
|
2658
1958
|
**/
|
|
2659
|
-
createPregenWalletPerType(
|
|
2660
|
-
return __async(this,
|
|
2661
|
-
|
|
2662
|
-
pregenId
|
|
2663
|
-
}) {
|
|
2664
|
-
const wallets = [];
|
|
2665
|
-
for (const type of yield this.getTypesToCreate(types)) {
|
|
2666
|
-
const wallet = yield this.createPregenWallet({ type, pregenId });
|
|
2667
|
-
wallets.push(wallet);
|
|
2668
|
-
}
|
|
2669
|
-
return wallets;
|
|
1959
|
+
createPregenWalletPerType(params) {
|
|
1960
|
+
return __async(this, null, function* () {
|
|
1961
|
+
return yield __privateGet(this, _pregenWalletService).createPregenWalletPerType(params);
|
|
2670
1962
|
});
|
|
2671
1963
|
}
|
|
2672
1964
|
/**
|
|
@@ -2677,70 +1969,8 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2677
1969
|
* @returns {[Wallet, string | null]} `[wallet, recoveryShare]` - the wallet object and the new recovery share.
|
|
2678
1970
|
**/
|
|
2679
1971
|
claimPregenWallets() {
|
|
2680
|
-
return __async(this, arguments, function* ({
|
|
2681
|
-
|
|
2682
|
-
} = {}) {
|
|
2683
|
-
var _a;
|
|
2684
|
-
this.requireApiKey();
|
|
2685
|
-
const pregenWallets = pregenId ? yield this.getPregenWallets({ pregenId }) : yield this.getPregenWallets();
|
|
2686
|
-
if (pregenWallets.length === 0) {
|
|
2687
|
-
return void 0;
|
|
2688
|
-
}
|
|
2689
|
-
const missingWallets = pregenWallets.filter((wallet) => !this.wallets[wallet.id]);
|
|
2690
|
-
if (missingWallets.length > 0) {
|
|
2691
|
-
throw new Error(
|
|
2692
|
-
`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(", ")}`
|
|
2693
|
-
);
|
|
2694
|
-
}
|
|
2695
|
-
let newRecoverySecret;
|
|
2696
|
-
const { walletIds } = yield this.ctx.client.claimPregenWallets({
|
|
2697
|
-
userId: this.userId,
|
|
2698
|
-
walletIds: pregenWallets.map((w) => w.id)
|
|
2699
|
-
});
|
|
2700
|
-
for (const walletId of walletIds) {
|
|
2701
|
-
const wallet = this.wallets[walletId];
|
|
2702
|
-
let refreshedShare;
|
|
2703
|
-
if (wallet.scheme === "ED25519") {
|
|
2704
|
-
const distributeRes = yield distributeNewShare({
|
|
2705
|
-
ctx: this.ctx,
|
|
2706
|
-
userId: this.userId,
|
|
2707
|
-
walletId: wallet.id,
|
|
2708
|
-
userShare: this.wallets[wallet.id].signer,
|
|
2709
|
-
emailProps: this.getBackupKitEmailProps(),
|
|
2710
|
-
partnerId: wallet.partnerId,
|
|
2711
|
-
isEnclaveUser: this.isEnclaveUser,
|
|
2712
|
-
walletScheme: wallet.scheme
|
|
2713
|
-
});
|
|
2714
|
-
if (distributeRes.length > 0) {
|
|
2715
|
-
newRecoverySecret = distributeRes;
|
|
2716
|
-
}
|
|
2717
|
-
} else {
|
|
2718
|
-
refreshedShare = yield this.refreshShare({
|
|
2719
|
-
walletId: wallet.id,
|
|
2720
|
-
share: this.wallets[wallet.id].signer,
|
|
2721
|
-
oldPartnerId: wallet.partnerId,
|
|
2722
|
-
newPartnerId: wallet.partnerId,
|
|
2723
|
-
redistributeBackupEncryptedShares: true
|
|
2724
|
-
});
|
|
2725
|
-
if (refreshedShare.recoverySecret) {
|
|
2726
|
-
newRecoverySecret = refreshedShare.recoverySecret;
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
this.wallets[wallet.id] = __spreadProps(__spreadValues({}, this.wallets[wallet.id]), {
|
|
2730
|
-
signer: (_a = refreshedShare == null ? void 0 : refreshedShare.signer) != null ? _a : wallet.signer,
|
|
2731
|
-
userId: this.userId,
|
|
2732
|
-
pregenIdentifier: void 0,
|
|
2733
|
-
pregenIdentifierType: void 0
|
|
2734
|
-
});
|
|
2735
|
-
const walletNoSigner = __spreadValues({}, this.wallets[wallet.id]);
|
|
2736
|
-
delete walletNoSigner.signer;
|
|
2737
|
-
dispatchEvent(ParaEvent.PREGEN_WALLET_CLAIMED, {
|
|
2738
|
-
wallet: walletNoSigner,
|
|
2739
|
-
recoverySecret: newRecoverySecret
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
|
-
yield this.setWallets(this.wallets);
|
|
2743
|
-
return newRecoverySecret;
|
|
1972
|
+
return __async(this, arguments, function* (params = {}) {
|
|
1973
|
+
return yield __privateGet(this, _pregenWalletService).claimPregenWallets(params);
|
|
2744
1974
|
});
|
|
2745
1975
|
}
|
|
2746
1976
|
/**
|
|
@@ -2750,24 +1980,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2750
1980
|
* @param {string} opts.newPregenIdentifier the new identtifier
|
|
2751
1981
|
* @param {TPregenIdentifierType} opts.newPregenIdentifierType: the new identifier type
|
|
2752
1982
|
**/
|
|
2753
|
-
updatePregenWalletIdentifier(
|
|
2754
|
-
return __async(this,
|
|
2755
|
-
|
|
2756
|
-
newPregenId
|
|
2757
|
-
}) {
|
|
2758
|
-
this.requireApiKey();
|
|
2759
|
-
const [newPregenIdentifierType, newPregenIdentifier] = toPregenTypeAndId(newPregenId);
|
|
2760
|
-
yield this.ctx.client.updatePregenWallet(walletId, {
|
|
2761
|
-
pregenIdentifier: newPregenIdentifier,
|
|
2762
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
2763
|
-
});
|
|
2764
|
-
if (!!this.wallets[walletId]) {
|
|
2765
|
-
this.wallets[walletId] = __spreadProps(__spreadValues({}, this.wallets[walletId]), {
|
|
2766
|
-
pregenIdentifier: newPregenIdentifier,
|
|
2767
|
-
pregenIdentifierType: newPregenIdentifierType
|
|
2768
|
-
});
|
|
2769
|
-
yield this.setWallets(this.wallets);
|
|
2770
|
-
}
|
|
1983
|
+
updatePregenWalletIdentifier(params) {
|
|
1984
|
+
return __async(this, null, function* () {
|
|
1985
|
+
return yield __privateGet(this, _pregenWalletService).updatePregenWalletIdentifier(params);
|
|
2771
1986
|
});
|
|
2772
1987
|
}
|
|
2773
1988
|
/**
|
|
@@ -2777,18 +1992,9 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2777
1992
|
* @param {TPregenIdentifierType} opts.pregenIdentifierType type of the string of the identifier of the user claiming the wallet
|
|
2778
1993
|
* @returns {boolean} whether the pregen wallet exists
|
|
2779
1994
|
**/
|
|
2780
|
-
hasPregenWallet(
|
|
2781
|
-
return __async(this,
|
|
2782
|
-
this.
|
|
2783
|
-
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
2784
|
-
const wallets = yield this.getPregenWallets({ pregenId });
|
|
2785
|
-
const wallet = wallets.find(
|
|
2786
|
-
(w) => w.pregenIdentifier === pregenIdentifier && w.pregenIdentifierType === pregenIdentifierType
|
|
2787
|
-
);
|
|
2788
|
-
if (!wallet) {
|
|
2789
|
-
return false;
|
|
2790
|
-
}
|
|
2791
|
-
return true;
|
|
1995
|
+
hasPregenWallet(params) {
|
|
1996
|
+
return __async(this, null, function* () {
|
|
1997
|
+
return yield __privateGet(this, _pregenWalletService).hasPregenWallet(params);
|
|
2792
1998
|
});
|
|
2793
1999
|
}
|
|
2794
2000
|
/**
|
|
@@ -2799,64 +2005,21 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2799
2005
|
* @returns {Promise<WalletEntity[]>} the array of found wallets
|
|
2800
2006
|
**/
|
|
2801
2007
|
getPregenWallets() {
|
|
2802
|
-
return __async(this, arguments, function* (
|
|
2803
|
-
this.
|
|
2804
|
-
const res = yield this.ctx.client.getPregenWallets(
|
|
2805
|
-
pregenId ? toPregenIds(pregenId) : this.pregenIds,
|
|
2806
|
-
this.isPortal(),
|
|
2807
|
-
this.userId
|
|
2808
|
-
);
|
|
2809
|
-
return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
|
|
2008
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2009
|
+
return yield __privateGet(this, _pregenWalletService).getPregenWallets(params);
|
|
2810
2010
|
});
|
|
2811
2011
|
}
|
|
2812
2012
|
createGuestWallets() {
|
|
2813
2013
|
return __async(this, null, function* () {
|
|
2814
|
-
|
|
2815
|
-
if (__privateGet(this, _isCreateGuestWalletsPending)) {
|
|
2816
|
-
error = new Error("Guest wallets creation already in progress");
|
|
2817
|
-
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2818
|
-
throw error;
|
|
2819
|
-
}
|
|
2820
|
-
if (this.isGuestMode) {
|
|
2821
|
-
error = new Error("Guest wallets already created");
|
|
2822
|
-
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error.message);
|
|
2823
|
-
throw error;
|
|
2824
|
-
}
|
|
2825
|
-
try {
|
|
2826
|
-
__privateSet(this, _isCreateGuestWalletsPending, true);
|
|
2827
|
-
const { supportedWalletTypes } = yield __privateMethod(this, _ParaCore_instances, assertPartner_fn).call(this);
|
|
2828
|
-
const wallets = [];
|
|
2829
|
-
const guestId = newUuid();
|
|
2830
|
-
for (const type of yield this.getTypesToCreate(
|
|
2831
|
-
supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
|
|
2832
|
-
)) {
|
|
2833
|
-
const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenId: { guestId } });
|
|
2834
|
-
wallets.push(wallet);
|
|
2835
|
-
}
|
|
2836
|
-
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, wallets);
|
|
2837
|
-
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2838
|
-
return wallets;
|
|
2839
|
-
} catch (error2) {
|
|
2840
|
-
dispatchEvent(ParaEvent.GUEST_WALLETS_CREATED, null, error2 == null ? void 0 : error2.message);
|
|
2841
|
-
__privateSet(this, _isCreateGuestWalletsPending, false);
|
|
2842
|
-
throw error2;
|
|
2843
|
-
}
|
|
2014
|
+
return yield __privateGet(this, _pregenWalletService).createGuestWallets();
|
|
2844
2015
|
});
|
|
2845
2016
|
}
|
|
2846
|
-
encodeWalletBase64(wallet) {
|
|
2847
|
-
const walletJson = JSON.stringify(wallet);
|
|
2848
|
-
const base64Wallet = Buffer.from(walletJson).toString("base64");
|
|
2849
|
-
return base64Wallet;
|
|
2850
|
-
}
|
|
2851
2017
|
/**
|
|
2852
2018
|
* Encodes the current wallets encoded in Base 64.
|
|
2853
2019
|
* @returns {string} the encoded wallet string
|
|
2854
2020
|
**/
|
|
2855
2021
|
getUserShare() {
|
|
2856
|
-
|
|
2857
|
-
return null;
|
|
2858
|
-
}
|
|
2859
|
-
return Object.values(this.wallets).map((wallet) => this.encodeWalletBase64(wallet)).join("-");
|
|
2022
|
+
return __privateGet(this, _walletService).getUserShare();
|
|
2860
2023
|
}
|
|
2861
2024
|
/**
|
|
2862
2025
|
* Sets the current wallets from a Base 64 string.
|
|
@@ -2864,24 +2027,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2864
2027
|
**/
|
|
2865
2028
|
setUserShare(base64Wallets) {
|
|
2866
2029
|
return __async(this, null, function* () {
|
|
2867
|
-
|
|
2868
|
-
return;
|
|
2869
|
-
}
|
|
2870
|
-
const base64WalletsSplit = base64Wallets.split("-");
|
|
2871
|
-
for (const base64Wallet of base64WalletsSplit) {
|
|
2872
|
-
const walletJson = Buffer.from(base64Wallet, "base64").toString();
|
|
2873
|
-
const wallet = migrateWallet(JSON.parse(walletJson));
|
|
2874
|
-
this.wallets[wallet.id] = wallet;
|
|
2875
|
-
yield this.setWallets(this.wallets);
|
|
2876
|
-
}
|
|
2030
|
+
return yield __privateGet(this, _walletService).setUserShare(base64Wallets);
|
|
2877
2031
|
});
|
|
2878
2032
|
}
|
|
2879
2033
|
getTransactionReviewUrl(transactionId, timeoutMs) {
|
|
2880
2034
|
return __async(this, null, function* () {
|
|
2035
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
2881
2036
|
return this.constructPortalUrl("txReview", {
|
|
2882
2037
|
pathId: transactionId,
|
|
2038
|
+
useLegacyUrl: authMethods.has(AuthMethod.PASSKEY),
|
|
2883
2039
|
params: {
|
|
2884
|
-
email: this.email,
|
|
2885
2040
|
timeoutMs: timeoutMs == null ? void 0 : timeoutMs.toString()
|
|
2886
2041
|
}
|
|
2887
2042
|
});
|
|
@@ -2896,6 +2051,11 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2896
2051
|
});
|
|
2897
2052
|
});
|
|
2898
2053
|
}
|
|
2054
|
+
getWalletBalance(params) {
|
|
2055
|
+
return __async(this, null, function* () {
|
|
2056
|
+
return yield __privateGet(this, _walletService).getWalletBalance(params);
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2899
2059
|
/**
|
|
2900
2060
|
* Signs a message using one of the current wallets.
|
|
2901
2061
|
*
|
|
@@ -2918,7 +2078,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
2918
2078
|
onPoll
|
|
2919
2079
|
}) {
|
|
2920
2080
|
var _a;
|
|
2921
|
-
this.assertIsValidWalletId(walletId);
|
|
2081
|
+
__privateGet(this, _walletService).assertIsValidWalletId(walletId);
|
|
2922
2082
|
const wallet = this.wallets[walletId];
|
|
2923
2083
|
let signerId = this.userId;
|
|
2924
2084
|
if (wallet.partnerId && !wallet.userId) {
|
|
@@ -3023,7 +2183,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3023
2183
|
onPoll
|
|
3024
2184
|
}) {
|
|
3025
2185
|
var _a;
|
|
3026
|
-
this.assertIsValidWalletId(walletId);
|
|
2186
|
+
__privateGet(this, _walletService).assertIsValidWalletId(walletId);
|
|
3027
2187
|
const wallet = this.wallets[walletId];
|
|
3028
2188
|
let signerId = this.userId;
|
|
3029
2189
|
if (wallet.partnerId && !wallet.userId) {
|
|
@@ -3129,12 +2289,7 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3129
2289
|
**/
|
|
3130
2290
|
keepSessionAlive() {
|
|
3131
2291
|
return __async(this, null, function* () {
|
|
3132
|
-
|
|
3133
|
-
yield this.ctx.client.keepSessionAlive(this.userId);
|
|
3134
|
-
return true;
|
|
3135
|
-
} catch (e) {
|
|
3136
|
-
return false;
|
|
3137
|
-
}
|
|
2292
|
+
return yield __privateGet(this, _sessionManagementService).keepSessionAlive();
|
|
3138
2293
|
});
|
|
3139
2294
|
}
|
|
3140
2295
|
/**
|
|
@@ -3144,10 +2299,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3144
2299
|
*/
|
|
3145
2300
|
exportSession({ excludeSigners = false } = {}) {
|
|
3146
2301
|
const sessionInfo = {
|
|
3147
|
-
authInfo: __privateGet(this,
|
|
2302
|
+
authInfo: __privateGet(this, _authService).authInfo,
|
|
3148
2303
|
userId: this.userId,
|
|
3149
2304
|
wallets: structuredClone(this.wallets),
|
|
3150
|
-
currentWalletIds: this.currentWalletIds,
|
|
2305
|
+
currentWalletIds: __privateGet(this, _walletService).currentWalletIds,
|
|
3151
2306
|
sessionCookie: this.retrieveSessionCookie(),
|
|
3152
2307
|
externalWallets: this.externalWallets
|
|
3153
2308
|
};
|
|
@@ -3165,10 +2320,25 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3165
2320
|
importSession(serializedInstanceBase64) {
|
|
3166
2321
|
return __async(this, null, function* () {
|
|
3167
2322
|
var _a, _b;
|
|
2323
|
+
yield waitForAuthStateChange({
|
|
2324
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2325
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => void 0 }],
|
|
2326
|
+
rejectPhases: [
|
|
2327
|
+
{
|
|
2328
|
+
phase: "authenticated",
|
|
2329
|
+
onPhase: () => new Error("Cannot import a session into a Para instance that already has an active session.")
|
|
2330
|
+
},
|
|
2331
|
+
{
|
|
2332
|
+
phase: "guest_mode",
|
|
2333
|
+
onPhase: () => new Error("Cannot import a session into a Para instance that is in guest mode.")
|
|
2334
|
+
}
|
|
2335
|
+
],
|
|
2336
|
+
waitForCoreAuthenticated: false
|
|
2337
|
+
});
|
|
3168
2338
|
const serializedInstance = Buffer.from(serializedInstanceBase64, "base64").toString("utf8");
|
|
3169
2339
|
const sessionInfo = jsonParse(serializedInstance);
|
|
3170
2340
|
const authInfo = (_a = sessionInfo.authInfo) != null ? _a : __privateMethod(this, _ParaCore_instances, toAuthInfo_fn).call(this, sessionInfo);
|
|
3171
|
-
yield
|
|
2341
|
+
yield __privateGet(this, _authService).setAuthInfo(authInfo);
|
|
3172
2342
|
yield this.setUserId(sessionInfo.userId);
|
|
3173
2343
|
yield this.setWallets(sessionInfo.wallets);
|
|
3174
2344
|
yield this.setExternalWallets(sessionInfo.externalWallets || {});
|
|
@@ -3189,7 +2359,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3189
2359
|
}
|
|
3190
2360
|
yield this.setCurrentWalletIds(currentWalletIds);
|
|
3191
2361
|
}
|
|
2362
|
+
__privateGet(this, _sessionManagementService).isImportedSession = true;
|
|
2363
|
+
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_IMPORTED_SESSION, JSON.stringify(true));
|
|
3192
2364
|
this.persistSessionCookie(sessionInfo.sessionCookie);
|
|
2365
|
+
__privateGet(this, _stateManager).send({ type: "SESSION_IMPORTED" });
|
|
3193
2366
|
});
|
|
3194
2367
|
}
|
|
3195
2368
|
/**
|
|
@@ -3198,22 +2371,12 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3198
2371
|
**/
|
|
3199
2372
|
getVerificationToken() {
|
|
3200
2373
|
return __async(this, null, function* () {
|
|
3201
|
-
|
|
3202
|
-
return sessionLookupId;
|
|
2374
|
+
return yield __privateGet(this, _sessionManagementService).getVerificationToken();
|
|
3203
2375
|
});
|
|
3204
2376
|
}
|
|
3205
2377
|
issueJwt() {
|
|
3206
|
-
return __async(this, arguments, function* (
|
|
3207
|
-
|
|
3208
|
-
return yield this.ctx.client.issueJwt({ keyIndex });
|
|
3209
|
-
} catch (error) {
|
|
3210
|
-
if (error.status === 403 || error.status === 401) {
|
|
3211
|
-
const errorMessage = "The user needs to be logged in to issue a JWT. Please log in and try again.";
|
|
3212
|
-
this.displayModalError(errorMessage);
|
|
3213
|
-
console.warn(errorMessage);
|
|
3214
|
-
}
|
|
3215
|
-
throw error;
|
|
3216
|
-
}
|
|
2378
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2379
|
+
return yield __privateGet(this, _sessionManagementService).issueJwt(params);
|
|
3217
2380
|
});
|
|
3218
2381
|
}
|
|
3219
2382
|
/**
|
|
@@ -3223,30 +2386,39 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3223
2386
|
**/
|
|
3224
2387
|
logout() {
|
|
3225
2388
|
return __async(this, arguments, function* ({ clearPregenWallets = false } = {}) {
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
yield this.
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
2389
|
+
yield __privateMethod(this, _ParaCore_instances, logout_fn).call(this, { clearPregenWallets });
|
|
2390
|
+
__privateGet(this, _pollingService).cancelAllPolling();
|
|
2391
|
+
yield __privateGet(this, _externalWalletService).disconnectAllExternalWallets();
|
|
2392
|
+
try {
|
|
2393
|
+
yield waitForAuthStateChange({
|
|
2394
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2395
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => void 0 }],
|
|
2396
|
+
rejectInErrorPhaseOnly: true,
|
|
2397
|
+
timeoutMs: 5e3
|
|
3234
2398
|
});
|
|
3235
|
-
|
|
3236
|
-
} else {
|
|
3237
|
-
this.wallets = {};
|
|
2399
|
+
} catch (e) {
|
|
3238
2400
|
}
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Cancels any in-progress authentication flow, returning the auth state machine
|
|
2405
|
+
* to its initial unauthenticated state. Does not affect existing sessions or stored data.
|
|
2406
|
+
*
|
|
2407
|
+
* Resolves once the auth state machine has settled back to `unauthenticated`.
|
|
2408
|
+
*/
|
|
2409
|
+
cancelAuthFlow() {
|
|
2410
|
+
return __async(this, null, function* () {
|
|
2411
|
+
if (this.authPhase === "unauthenticated" || this.authPhase === "error") {
|
|
2412
|
+
return;
|
|
3249
2413
|
}
|
|
2414
|
+
const settled = waitForAuthStateChange({
|
|
2415
|
+
stateManager: __privateGet(this, _stateManager),
|
|
2416
|
+
resolvePhases: [{ phase: "unauthenticated", onPhase: () => true }],
|
|
2417
|
+
rejectInErrorPhaseOnly: true,
|
|
2418
|
+
timeoutMs: 5e3
|
|
2419
|
+
});
|
|
2420
|
+
__privateGet(this, _stateManager).send({ type: "CANCEL" });
|
|
2421
|
+
yield settled;
|
|
3250
2422
|
});
|
|
3251
2423
|
}
|
|
3252
2424
|
get toStringAdditions() {
|
|
@@ -3279,16 +2451,16 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3279
2451
|
partnerId: (_a = this.partner) == null ? void 0 : _a.id,
|
|
3280
2452
|
supportedWalletTypes: (_b = this.partner) == null ? void 0 : _b.supportedWalletTypes,
|
|
3281
2453
|
cosmosPrefix: (_c = this.partner) == null ? void 0 : _c.cosmosPrefix,
|
|
3282
|
-
authInfo: __privateGet(this,
|
|
2454
|
+
authInfo: __privateGet(this, _authService).authInfo,
|
|
3283
2455
|
isGuestMode: this.isGuestMode,
|
|
3284
2456
|
userId: this.userId,
|
|
3285
2457
|
pregenIds: this.pregenIds,
|
|
3286
|
-
currentWalletIds: this.currentWalletIds,
|
|
3287
|
-
guestWalletIds: __privateGet(this,
|
|
2458
|
+
currentWalletIds: __privateGet(this, _walletService).currentWalletIds,
|
|
2459
|
+
guestWalletIds: __privateGet(this, _pregenWalletService).guestWalletIds,
|
|
3288
2460
|
wallets: redactedWallets,
|
|
3289
2461
|
externalWallets: redactedExternalWallets,
|
|
3290
2462
|
loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
|
|
3291
|
-
|
|
2463
|
+
isSetup: this.isSetup
|
|
3292
2464
|
}, this.toStringAdditions), {
|
|
3293
2465
|
ctx: {
|
|
3294
2466
|
apiKey: this.ctx.apiKey,
|
|
@@ -3304,90 +2476,13 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3304
2476
|
return `Para ${JSON.stringify(obj, null, 2)}`;
|
|
3305
2477
|
}
|
|
3306
2478
|
devLog(...s) {
|
|
3307
|
-
if (this.ctx.env === Environment.DEV || this.ctx.env === Environment.SANDBOX) {
|
|
2479
|
+
if (this.ctx.env === Environment.DEV || this.ctx.env === Environment.SANDBOX || !!__privateGet(this, _debugLogsEnabled)) {
|
|
3308
2480
|
console.log(...s);
|
|
3309
2481
|
}
|
|
3310
2482
|
}
|
|
3311
2483
|
getNewCredentialAndUrl() {
|
|
3312
|
-
return __async(this, arguments, function* ({
|
|
3313
|
-
|
|
3314
|
-
isForNewDevice = false,
|
|
3315
|
-
portalTheme,
|
|
3316
|
-
shorten = false
|
|
3317
|
-
} = {}) {
|
|
3318
|
-
const userAuthMethods = yield this.supportedUserAuthMethods();
|
|
3319
|
-
const isEnclaveUser = userAuthMethods.has(AuthMethod.BASIC_LOGIN);
|
|
3320
|
-
const isAddingBasicLogin = optsAuthMethod === "BASIC_LOGIN";
|
|
3321
|
-
if (isEnclaveUser && isAddingBasicLogin) {
|
|
3322
|
-
throw new Error("That user is already using basic login");
|
|
3323
|
-
}
|
|
3324
|
-
if (isEnclaveUser || isAddingBasicLogin) {
|
|
3325
|
-
isForNewDevice = true;
|
|
3326
|
-
}
|
|
3327
|
-
const authMethods = optsAuthMethod ? [optsAuthMethod] : isForNewDevice ? ["PASSKEY", "PIN", "PASSWORD"] : ["PASSKEY"];
|
|
3328
|
-
this.assertIsAuthSet();
|
|
3329
|
-
let passkeyId, passwordId, urlType, credentialId;
|
|
3330
|
-
if (!isAddingBasicLogin) {
|
|
3331
|
-
const canAddPasswordOrPIN = !userAuthMethods.has(AuthMethod.PASSWORD) && !userAuthMethods.has(AuthMethod.PIN);
|
|
3332
|
-
if (authMethods.includes("PASSKEY") && (yield this.isPasskeySupported())) {
|
|
3333
|
-
({
|
|
3334
|
-
data: { id: passkeyId }
|
|
3335
|
-
} = yield this.ctx.client.addSessionPublicKey(this.userId, {
|
|
3336
|
-
status: AuthMethodStatus.PENDING,
|
|
3337
|
-
type: PublicKeyType.WEB
|
|
3338
|
-
}));
|
|
3339
|
-
urlType = "createAuth";
|
|
3340
|
-
}
|
|
3341
|
-
if (authMethods.includes("PASSWORD")) {
|
|
3342
|
-
if (!canAddPasswordOrPIN) {
|
|
3343
|
-
if (optsAuthMethod === "PASSWORD") throw new Error("A user cannot have more than one password or PIN.");
|
|
3344
|
-
} else {
|
|
3345
|
-
({
|
|
3346
|
-
data: { id: passwordId }
|
|
3347
|
-
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3348
|
-
status: AuthMethodStatus.PENDING
|
|
3349
|
-
}));
|
|
3350
|
-
urlType = "createPassword";
|
|
3351
|
-
}
|
|
3352
|
-
}
|
|
3353
|
-
if (authMethods.includes("PIN")) {
|
|
3354
|
-
if (!canAddPasswordOrPIN) {
|
|
3355
|
-
if (optsAuthMethod === "PIN") throw new Error("A user cannot have more than one password or PIN.");
|
|
3356
|
-
} else {
|
|
3357
|
-
({
|
|
3358
|
-
data: { id: passwordId }
|
|
3359
|
-
} = yield this.ctx.client.addSessionPasswordPublicKey(this.userId, {
|
|
3360
|
-
status: AuthMethodStatus.PENDING
|
|
3361
|
-
}));
|
|
3362
|
-
urlType = "createPIN";
|
|
3363
|
-
}
|
|
3364
|
-
}
|
|
3365
|
-
credentialId = passkeyId != null ? passkeyId : passwordId;
|
|
3366
|
-
if (this.isNativePasskey && authMethods.includes("PASSKEY")) {
|
|
3367
|
-
return { credentialId };
|
|
3368
|
-
}
|
|
3369
|
-
}
|
|
3370
|
-
const { sessionId } = yield this.touchSession();
|
|
3371
|
-
const url = (isForNewDevice || urlType) && (yield this.constructPortalUrl(isForNewDevice ? "addNewCredential" : urlType, {
|
|
3372
|
-
isForNewDevice,
|
|
3373
|
-
pathId: credentialId,
|
|
3374
|
-
portalTheme,
|
|
3375
|
-
shorten,
|
|
3376
|
-
sessionId: isForNewDevice ? sessionId : void 0,
|
|
3377
|
-
addNewCredentialType: optsAuthMethod,
|
|
3378
|
-
addNewCredentialPasskeyId: passkeyId,
|
|
3379
|
-
addNewCredentialPasswordId: passwordId
|
|
3380
|
-
}));
|
|
3381
|
-
return __spreadValues({ credentialId }, url ? { url } : {});
|
|
3382
|
-
});
|
|
3383
|
-
}
|
|
3384
|
-
addCredential(_0) {
|
|
3385
|
-
return __async(this, arguments, function* ({ authMethod }) {
|
|
3386
|
-
if (authMethod === "PASSKEY" && !(yield this.isPasskeySupported())) {
|
|
3387
|
-
throw new Error("Passkeys are not supported.");
|
|
3388
|
-
}
|
|
3389
|
-
const { url } = yield this.getNewCredentialAndUrl({ isForNewDevice: true, authMethod });
|
|
3390
|
-
return url;
|
|
2484
|
+
return __async(this, arguments, function* (params = {}) {
|
|
2485
|
+
return yield __privateGet(this, _authService).getNewCredentialAndUrl(params);
|
|
3391
2486
|
});
|
|
3392
2487
|
}
|
|
3393
2488
|
/**
|
|
@@ -3398,92 +2493,34 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3398
2493
|
* @param {Theme} opts.portalTheme the Para Portal theme to apply to the password creation URL, if other than the default theme
|
|
3399
2494
|
* @returns {SignUpOrLogInResponse} an object in the form of either: `{ stage: 'verify' }` or `{ stage: 'login'; passkeyUrl?: string; passwordUrl?: string; biometricHints?: BiometricLocationHint[] }`
|
|
3400
2495
|
*/
|
|
3401
|
-
getLoginUrl(
|
|
3402
|
-
return __async(this,
|
|
3403
|
-
|
|
3404
|
-
shorten = false,
|
|
3405
|
-
portalTheme,
|
|
3406
|
-
sessionId
|
|
3407
|
-
}) {
|
|
3408
|
-
if (!sessionId) {
|
|
3409
|
-
sessionId = (yield this.touchSession()).sessionLookupId;
|
|
3410
|
-
}
|
|
3411
|
-
this.assertIsAuthSet();
|
|
3412
|
-
let urlType;
|
|
3413
|
-
switch (authMethod) {
|
|
3414
|
-
case "PASSKEY":
|
|
3415
|
-
urlType = "loginAuth";
|
|
3416
|
-
break;
|
|
3417
|
-
case "PASSWORD":
|
|
3418
|
-
urlType = "loginPassword";
|
|
3419
|
-
break;
|
|
3420
|
-
case "PIN":
|
|
3421
|
-
urlType = "loginPIN";
|
|
3422
|
-
break;
|
|
3423
|
-
case "BASIC_LOGIN":
|
|
3424
|
-
urlType = this.authInfo.authType === "externalWallet" ? "loginExternalWallet" : "loginOTP";
|
|
3425
|
-
break;
|
|
3426
|
-
default:
|
|
3427
|
-
throw new Error(`invalid authentication method: '${authMethod}'`);
|
|
3428
|
-
}
|
|
3429
|
-
return this.constructPortalUrl(urlType, {
|
|
3430
|
-
sessionId,
|
|
3431
|
-
shorten,
|
|
3432
|
-
portalTheme
|
|
3433
|
-
});
|
|
2496
|
+
getLoginUrl(params) {
|
|
2497
|
+
return __async(this, null, function* () {
|
|
2498
|
+
return yield __privateGet(this, _portalUrlService).getLoginUrl(params);
|
|
3434
2499
|
});
|
|
3435
2500
|
}
|
|
3436
2501
|
prepareLogin() {
|
|
3437
2502
|
return __async(this, null, function* () {
|
|
3438
|
-
|
|
3439
|
-
const { sessionLookupId } = yield this.touchSession(true);
|
|
3440
|
-
if (!this.loginEncryptionKeyPair) {
|
|
3441
|
-
yield this.setLoginEncryptionKeyPair();
|
|
3442
|
-
}
|
|
3443
|
-
return sessionLookupId;
|
|
2503
|
+
return __privateGet(this, _authService).prepareLogin();
|
|
3444
2504
|
});
|
|
3445
2505
|
}
|
|
3446
|
-
signUpOrLogIn(
|
|
2506
|
+
signUpOrLogIn(params) {
|
|
3447
2507
|
return __async(this, null, function* () {
|
|
3448
|
-
|
|
3449
|
-
let serverAuthState;
|
|
3450
|
-
try {
|
|
3451
|
-
serverAuthState = yield this.ctx.client.signUpOrLogIn(__spreadValues(__spreadValues({}, auth), this.getVerificationEmailProps()));
|
|
3452
|
-
} catch (error) {
|
|
3453
|
-
if (error.message.includes("max beta users reached")) {
|
|
3454
|
-
this.displayModalError(
|
|
3455
|
-
`50 user limit reached. [Go to Production.](https://docs.getpara.com/v2/general/checklist#go-live-checklist)`
|
|
3456
|
-
);
|
|
3457
|
-
}
|
|
3458
|
-
throw error;
|
|
3459
|
-
}
|
|
3460
|
-
const authInfo = serverAuthState.auth;
|
|
3461
|
-
if (this.fetchPregenWalletsOverride && isPregenAuth(authInfo)) {
|
|
3462
|
-
const { userShare } = yield this.fetchPregenWalletsOverride({ pregenId: authInfo });
|
|
3463
|
-
if (userShare) {
|
|
3464
|
-
yield this.setUserShare(userShare);
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, __spreadValues({}, urlOptions));
|
|
2508
|
+
return yield __privateGet(this, _authService).signUpOrLogIn(params);
|
|
3468
2509
|
});
|
|
3469
2510
|
}
|
|
3470
|
-
|
|
2511
|
+
authenticateWithEmailOrPhone(params) {
|
|
3471
2512
|
return __async(this, null, function* () {
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
this
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
throw new Error("Account already exists.");
|
|
3484
|
-
}
|
|
3485
|
-
yield this.touchSession(true);
|
|
3486
|
-
return __privateMethod(this, _ParaCore_instances, prepareAuthState_fn).call(this, serverAuthState, urlOptions);
|
|
2513
|
+
return yield __privateGet(this, _authService).authenticateWithEmailOrPhone(params);
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
authenticateWithOAuth(params) {
|
|
2517
|
+
return __async(this, null, function* () {
|
|
2518
|
+
return yield __privateGet(this, _authService).authenticateWithOAuth(params);
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2521
|
+
verifyNewAccount(params) {
|
|
2522
|
+
return __async(this, null, function* () {
|
|
2523
|
+
return yield __privateGet(this, _authService).verifyNewAccount(params);
|
|
3487
2524
|
});
|
|
3488
2525
|
}
|
|
3489
2526
|
getLinkedAccounts() {
|
|
@@ -3569,10 +2606,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3569
2606
|
});
|
|
3570
2607
|
}
|
|
3571
2608
|
verifyLink() {
|
|
3572
|
-
return __async(this, arguments, function* (
|
|
3573
|
-
var
|
|
2609
|
+
return __async(this, arguments, function* (_e = {}) {
|
|
2610
|
+
var _f = _e, {
|
|
3574
2611
|
accountLinkInProgress = __privateMethod(this, _ParaCore_instances, assertIsLinkingAccount_fn).call(this)
|
|
3575
|
-
} =
|
|
2612
|
+
} = _f, opts = __objRest(_f, [
|
|
3576
2613
|
"accountLinkInProgress"
|
|
3577
2614
|
]);
|
|
3578
2615
|
try {
|
|
@@ -3639,8 +2676,10 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3639
2676
|
if (args.shouldOpenPopup) {
|
|
3640
2677
|
this.popupWindow = yield this.platformUtils.openPopup("about:blank", { type: PopupType.EXPORT_PRIVATE_KEY });
|
|
3641
2678
|
}
|
|
2679
|
+
const authMethods = yield this.supportedUserAuthMethods();
|
|
3642
2680
|
const exportPrivateKeyUrl = yield this.constructPortalUrl("exportPrivateKey", {
|
|
3643
|
-
pathId: walletId
|
|
2681
|
+
pathId: walletId,
|
|
2682
|
+
useLegacyUrl: authMethods.has(AuthMethod.PASSKEY)
|
|
3644
2683
|
});
|
|
3645
2684
|
if (args.shouldOpenPopup) {
|
|
3646
2685
|
this.popupWindow.location.href = exportPrivateKeyUrl;
|
|
@@ -3652,7 +2691,15 @@ Need help? Visit: https://docs.getpara.com or contact support
|
|
|
3652
2691
|
});
|
|
3653
2692
|
}
|
|
3654
2693
|
};
|
|
3655
|
-
|
|
2694
|
+
_stateManager = new WeakMap();
|
|
2695
|
+
_authService = new WeakMap();
|
|
2696
|
+
_walletService = new WeakMap();
|
|
2697
|
+
_externalWalletService = new WeakMap();
|
|
2698
|
+
_pregenWalletService = new WeakMap();
|
|
2699
|
+
_pollingService = new WeakMap();
|
|
2700
|
+
_portalUrlService = new WeakMap();
|
|
2701
|
+
_sessionManagementService = new WeakMap();
|
|
2702
|
+
_debugLogsEnabled = new WeakMap();
|
|
3656
2703
|
_ParaCore_instances = new WeakSet();
|
|
3657
2704
|
assertPartner_fn = function() {
|
|
3658
2705
|
return __async(this, null, function* () {
|
|
@@ -3666,27 +2713,6 @@ assertPartner_fn = function() {
|
|
|
3666
2713
|
return this.partner;
|
|
3667
2714
|
});
|
|
3668
2715
|
};
|
|
3669
|
-
guestWalletIds_get = function() {
|
|
3670
|
-
var _a, _b, _c;
|
|
3671
|
-
if (!((_a = this.partner) == null ? void 0 : _a.supportedWalletTypes)) {
|
|
3672
|
-
return {};
|
|
3673
|
-
}
|
|
3674
|
-
const guestId = (_c = (_b = this.pregenIds) == null ? void 0 : _b.GUEST_ID) == null ? void 0 : _c[0];
|
|
3675
|
-
return !!guestId ? Object.entries(this.wallets).reduce((acc, [id, wallet]) => {
|
|
3676
|
-
if (wallet.isPregen && !wallet.userId && wallet.pregenIdentifierType === "GUEST_ID" && wallet.pregenIdentifier === guestId) {
|
|
3677
|
-
return __spreadValues(__spreadValues({}, acc), getEquivalentTypes(wallet.type).filter((type) => this.partner.supportedWalletTypes.some((entry) => entry.type === type)).reduce((acc2, eqType) => {
|
|
3678
|
-
var _a2;
|
|
3679
|
-
return __spreadProps(__spreadValues({}, acc2), { [eqType]: [.../* @__PURE__ */ new Set([...(_a2 = acc2[eqType]) != null ? _a2 : [], id])] });
|
|
3680
|
-
}, {}));
|
|
3681
|
-
}
|
|
3682
|
-
return acc;
|
|
3683
|
-
}, {}) : {};
|
|
3684
|
-
};
|
|
3685
|
-
guestWalletIdsArray_get = function() {
|
|
3686
|
-
return Object.entries(__privateGet(this, _ParaCore_instances, guestWalletIds_get)).reduce((acc, [type, ids]) => {
|
|
3687
|
-
return [...acc, ...ids.map((id) => [id, type])];
|
|
3688
|
-
}, []);
|
|
3689
|
-
};
|
|
3690
2716
|
toAuthInfo_fn = function({
|
|
3691
2717
|
email,
|
|
3692
2718
|
phone,
|
|
@@ -3718,27 +2744,6 @@ toAuthInfo_fn = function({
|
|
|
3718
2744
|
}
|
|
3719
2745
|
return extractAuthInfo(auth);
|
|
3720
2746
|
};
|
|
3721
|
-
setAuthInfo_fn = function(authInfo) {
|
|
3722
|
-
return __async(this, null, function* () {
|
|
3723
|
-
__privateSet(this, _authInfo, authInfo);
|
|
3724
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_AUTH_INFO, JSON.stringify(authInfo));
|
|
3725
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_EMAIL);
|
|
3726
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_PHONE);
|
|
3727
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_COUNTRY_CODE);
|
|
3728
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_FARCASTER_USERNAME);
|
|
3729
|
-
yield this.localStorageRemoveItem(constants.LOCAL_STORAGE_TELEGRAM_USER_ID);
|
|
3730
|
-
});
|
|
3731
|
-
};
|
|
3732
|
-
getPartner_fn = function(partnerId) {
|
|
3733
|
-
return __async(this, null, function* () {
|
|
3734
|
-
if (this.isPartnerOptional && !partnerId) {
|
|
3735
|
-
return void 0;
|
|
3736
|
-
}
|
|
3737
|
-
const res = yield this.ctx.client.getPartner(partnerId);
|
|
3738
|
-
this.partner = res.data.partner;
|
|
3739
|
-
return this.partner;
|
|
3740
|
-
});
|
|
3741
|
-
};
|
|
3742
2747
|
assertIsLinkingAccount_fn = function(types) {
|
|
3743
2748
|
if (!this.accountLinkInProgress || this.accountLinkInProgress.isComplete) {
|
|
3744
2749
|
throw new Error("no account linking in progress");
|
|
@@ -3758,49 +2763,6 @@ assertIsLinkingAccountOrStart_fn = function(type) {
|
|
|
3758
2763
|
return yield this.linkAccount({ type });
|
|
3759
2764
|
});
|
|
3760
2765
|
};
|
|
3761
|
-
getOAuthUrl_fn = function(_0) {
|
|
3762
|
-
return __async(this, arguments, function* ({
|
|
3763
|
-
method,
|
|
3764
|
-
appScheme,
|
|
3765
|
-
accountLinkInProgress,
|
|
3766
|
-
sessionLookupId,
|
|
3767
|
-
encryptionKey,
|
|
3768
|
-
portalCallbackParams
|
|
3769
|
-
}) {
|
|
3770
|
-
if (!accountLinkInProgress && !this.isPortal()) {
|
|
3771
|
-
return yield this.constructPortalUrl("oAuth", { sessionId: sessionLookupId, oAuthMethod: method, appScheme });
|
|
3772
|
-
}
|
|
3773
|
-
const [portalSessionLookupId, callback] = yield Promise.all([
|
|
3774
|
-
this.isPortal() ? this.touchSession(true).then((s) => s.sessionLookupId) : Promise.resolve(void 0),
|
|
3775
|
-
!accountLinkInProgress ? this.constructPortalUrl("oAuthCallback", __spreadValues({
|
|
3776
|
-
sessionId: sessionLookupId,
|
|
3777
|
-
oAuthMethod: method,
|
|
3778
|
-
appScheme,
|
|
3779
|
-
thisDevice: {
|
|
3780
|
-
sessionId: sessionLookupId,
|
|
3781
|
-
encryptionKey
|
|
3782
|
-
}
|
|
3783
|
-
}, this.isPortal() && {
|
|
3784
|
-
params: portalCallbackParams,
|
|
3785
|
-
// Build callback for legacy portal if needed
|
|
3786
|
-
useLegacyUrl: typeof window !== "undefined" ? window.location.host.includes("usecapsule") : false
|
|
3787
|
-
})) : Promise.resolve(false)
|
|
3788
|
-
]);
|
|
3789
|
-
return constructUrl({
|
|
3790
|
-
base: getBaseOAuthUrl(this.ctx.env),
|
|
3791
|
-
path: `/auth/${method.toLowerCase()}`,
|
|
3792
|
-
params: __spreadValues(__spreadValues({
|
|
3793
|
-
apiKey: this.ctx.apiKey,
|
|
3794
|
-
origin: typeof window !== "undefined" ? window.location.origin : void 0,
|
|
3795
|
-
sessionLookupId,
|
|
3796
|
-
portalSessionLookupId,
|
|
3797
|
-
appScheme
|
|
3798
|
-
}, accountLinkInProgress ? {
|
|
3799
|
-
linkedAccountId: this.accountLinkInProgress.id
|
|
3800
|
-
} : {}), callback && { callback })
|
|
3801
|
-
});
|
|
3802
|
-
});
|
|
3803
|
-
};
|
|
3804
2766
|
waitForLoginProcess_fn = function() {
|
|
3805
2767
|
return __async(this, arguments, function* ({
|
|
3806
2768
|
isCanceled = () => false,
|
|
@@ -3828,7 +2790,7 @@ waitForLoginProcess_fn = function() {
|
|
|
3828
2790
|
var _a;
|
|
3829
2791
|
if (!this.isExternalWalletAuth && !isSwitchingWallets) {
|
|
3830
2792
|
this.devLog("[waitForLoginProcess] Clearing external wallets");
|
|
3831
|
-
this.externalWallets = {};
|
|
2793
|
+
__privateGet(this, _externalWalletService).externalWallets = {};
|
|
3832
2794
|
}
|
|
3833
2795
|
let pollCount = 0;
|
|
3834
2796
|
while (true) {
|
|
@@ -3873,7 +2835,7 @@ waitForLoginProcess_fn = function() {
|
|
|
3873
2835
|
continue;
|
|
3874
2836
|
}
|
|
3875
2837
|
this.devLog("[waitForLoginProcess] Authentication check passed, setting up user");
|
|
3876
|
-
session = yield this.userSetupAfterLogin();
|
|
2838
|
+
session = yield this.userSetupAfterLogin(session);
|
|
3877
2839
|
const needsWallet = (_a = session.needsWallet) != null ? _a : false;
|
|
3878
2840
|
this.devLog("[waitForLoginProcess] User setup complete", { needsWallet });
|
|
3879
2841
|
if (isSwitchingWallets) {
|
|
@@ -3898,7 +2860,9 @@ waitForLoginProcess_fn = function() {
|
|
|
3898
2860
|
}
|
|
3899
2861
|
}
|
|
3900
2862
|
this.devLog("[waitForLoginProcess] Getting transmission key shares");
|
|
3901
|
-
const tempSharesRes = yield this.getTransmissionKeyShares(
|
|
2863
|
+
const tempSharesRes = yield this.getTransmissionKeyShares({
|
|
2864
|
+
sessionLookupId: session.sessionLookupId
|
|
2865
|
+
});
|
|
3902
2866
|
this.devLog("[waitForLoginProcess] Transmission shares received", {
|
|
3903
2867
|
shareCount: tempSharesRes.data.temporaryShares.length,
|
|
3904
2868
|
shares: tempSharesRes.data.temporaryShares.map((s) => ({
|
|
@@ -3965,224 +2929,41 @@ waitForLoginProcess_fn = function() {
|
|
|
3965
2929
|
});
|
|
3966
2930
|
});
|
|
3967
2931
|
};
|
|
3968
|
-
|
|
3969
|
-
return __async(this,
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
this.
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
);
|
|
3977
|
-
const [pregenIdentifierType, pregenIdentifier] = toPregenTypeAndId(pregenId);
|
|
3978
|
-
let keygenRes;
|
|
3979
|
-
switch (walletType) {
|
|
3980
|
-
case "SOLANA":
|
|
3981
|
-
keygenRes = yield this.platformUtils.ed25519PreKeygen(
|
|
3982
|
-
this.ctx,
|
|
3983
|
-
pregenIdentifier,
|
|
3984
|
-
pregenIdentifierType,
|
|
3985
|
-
this.retrieveSessionCookie()
|
|
3986
|
-
);
|
|
3987
|
-
break;
|
|
3988
|
-
default:
|
|
3989
|
-
keygenRes = yield this.platformUtils.preKeygen(
|
|
3990
|
-
this.ctx,
|
|
3991
|
-
void 0,
|
|
3992
|
-
pregenIdentifier,
|
|
3993
|
-
pregenIdentifierType,
|
|
3994
|
-
walletType,
|
|
3995
|
-
null,
|
|
3996
|
-
this.retrieveSessionCookie()
|
|
3997
|
-
);
|
|
3998
|
-
break;
|
|
3999
|
-
}
|
|
4000
|
-
const { signer, walletId } = keygenRes;
|
|
4001
|
-
this.wallets[walletId] = {
|
|
4002
|
-
id: walletId,
|
|
4003
|
-
signer,
|
|
4004
|
-
scheme: walletType === "SOLANA" ? "ED25519" : "DKLS",
|
|
4005
|
-
type: walletType,
|
|
4006
|
-
isPregen: true,
|
|
4007
|
-
pregenIdentifier,
|
|
4008
|
-
pregenIdentifierType
|
|
4009
|
-
};
|
|
4010
|
-
yield this.waitForPregenWalletAddress(walletId);
|
|
4011
|
-
yield this.populatePregenWalletAddresses();
|
|
4012
|
-
return this.wallets[walletId];
|
|
4013
|
-
});
|
|
4014
|
-
};
|
|
4015
|
-
_isCreateGuestWalletsPending = new WeakMap();
|
|
4016
|
-
prepareAuthState_fn = function(_0) {
|
|
4017
|
-
return __async(this, arguments, function* (serverAuthState, opts = {}) {
|
|
4018
|
-
var _a, _b;
|
|
4019
|
-
if (!opts.sessionLookupId && serverAuthState.stage === "login" && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(AuthMethod.PIN))))) {
|
|
4020
|
-
opts.sessionLookupId = yield this.prepareLogin();
|
|
4021
|
-
}
|
|
4022
|
-
const { auth, externalWallet, userId, displayName, pfpUrl, username } = serverAuthState;
|
|
4023
|
-
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(
|
|
4024
|
-
Object.entries({
|
|
4025
|
-
displayName,
|
|
4026
|
-
pfpUrl,
|
|
4027
|
-
username,
|
|
4028
|
-
externalWallet
|
|
4029
|
-
}).filter(([_, v]) => !!v)
|
|
4030
|
-
));
|
|
4031
|
-
yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
|
|
4032
|
-
yield this.assertIsAuthSet();
|
|
4033
|
-
if (!!externalWallet) {
|
|
4034
|
-
yield this.setExternalWallet([externalWallet]);
|
|
4035
|
-
}
|
|
4036
|
-
if (!!userId) {
|
|
4037
|
-
yield this.setUserId(userId);
|
|
2932
|
+
logout_fn = function() {
|
|
2933
|
+
return __async(this, arguments, function* ({
|
|
2934
|
+
clearPregenWallets = false,
|
|
2935
|
+
skipStateReset = false
|
|
2936
|
+
} = {}) {
|
|
2937
|
+
const isSessionActive = yield this.isSessionActive();
|
|
2938
|
+
if (!isSessionActive && !skipStateReset) {
|
|
2939
|
+
__privateGet(this, _stateManager).send({ type: "LOGOUT" });
|
|
4038
2940
|
}
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
case "verify":
|
|
4046
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareVerificationState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), {
|
|
4047
|
-
sessionLookupId: opts.sessionLookupId
|
|
4048
|
-
}));
|
|
4049
|
-
break;
|
|
4050
|
-
case "login":
|
|
4051
|
-
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4052
|
-
authState = serverAuthState;
|
|
4053
|
-
break;
|
|
4054
|
-
}
|
|
4055
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareLoginState_fn).call(this, serverAuthState, __spreadProps(__spreadValues({}, opts), { sessionLookupId: opts.sessionLookupId }));
|
|
4056
|
-
break;
|
|
4057
|
-
case "signup":
|
|
4058
|
-
if (externalWallet && !(externalWallet == null ? void 0 : externalWallet.withFullParaAuth)) {
|
|
4059
|
-
authState = serverAuthState;
|
|
4060
|
-
break;
|
|
2941
|
+
yield this.ctx.client.logout();
|
|
2942
|
+
yield this.clearStorage();
|
|
2943
|
+
if (!clearPregenWallets) {
|
|
2944
|
+
Object.entries(this.wallets).forEach(([id, wallet]) => {
|
|
2945
|
+
if (!wallet.pregenIdentifier) {
|
|
2946
|
+
delete this.wallets[id];
|
|
4061
2947
|
}
|
|
4062
|
-
authState = yield __privateMethod(this, _ParaCore_instances, prepareSignUpState_fn).call(this, serverAuthState, opts);
|
|
4063
|
-
break;
|
|
4064
|
-
}
|
|
4065
|
-
return authState;
|
|
4066
|
-
});
|
|
4067
|
-
};
|
|
4068
|
-
prepareDoneState_fn = function(doneState) {
|
|
4069
|
-
return __async(this, null, function* () {
|
|
4070
|
-
let isSLOPossible = doneState.authMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
4071
|
-
this.isEnclaveUser = isSLOPossible;
|
|
4072
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_ENCLAVE_USER, JSON.stringify(isSLOPossible));
|
|
4073
|
-
return doneState;
|
|
4074
|
-
});
|
|
4075
|
-
};
|
|
4076
|
-
prepareVerificationState_fn = function(_0, _1) {
|
|
4077
|
-
return __async(this, arguments, function* (verifyState, {
|
|
4078
|
-
useShortUrls: shorten = false,
|
|
4079
|
-
portalTheme,
|
|
4080
|
-
sessionLookupId
|
|
4081
|
-
}) {
|
|
4082
|
-
var _a;
|
|
4083
|
-
let isSLOPossible = false;
|
|
4084
|
-
if (verifyState.nextStage === "login") {
|
|
4085
|
-
isSLOPossible = verifyState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
4086
|
-
} else if (verifyState.nextStage === "signup") {
|
|
4087
|
-
isSLOPossible = verifyState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
4088
|
-
}
|
|
4089
|
-
this.isEnclaveUser = isSLOPossible;
|
|
4090
|
-
yield this.localStorageSetItem(constants.LOCAL_STORAGE_IS_ENCLAVE_USER, JSON.stringify(isSLOPossible));
|
|
4091
|
-
const isExternalWalletFullAuth = (_a = verifyState.externalWallet) == null ? void 0 : _a.withFullParaAuth;
|
|
4092
|
-
return __spreadValues(__spreadValues({}, verifyState), isSLOPossible || isExternalWalletFullAuth ? {
|
|
4093
|
-
loginUrl: yield this.getLoginUrl({
|
|
4094
|
-
authMethod: AuthMethod.BASIC_LOGIN,
|
|
4095
|
-
sessionId: sessionLookupId,
|
|
4096
|
-
shorten,
|
|
4097
|
-
portalTheme
|
|
4098
|
-
})
|
|
4099
|
-
} : {});
|
|
4100
|
-
});
|
|
4101
|
-
};
|
|
4102
|
-
prepareLoginState_fn = function(_0, _1) {
|
|
4103
|
-
return __async(this, arguments, function* (loginState, {
|
|
4104
|
-
useShortUrls: shorten = false,
|
|
4105
|
-
portalTheme,
|
|
4106
|
-
sessionLookupId
|
|
4107
|
-
}) {
|
|
4108
|
-
const _a = loginState, { loginAuthMethods = [], hasPasswordWithoutPIN } = _a, authState = __objRest(_a, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
4109
|
-
const isPasskeySupported = yield this.isPasskeySupported(), isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.isNativePasskey, isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN, isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
|
|
4110
|
-
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
4111
|
-
isPasskeySupported,
|
|
4112
|
-
loginAuthMethods
|
|
4113
|
-
}), isPasskeyPossible ? {
|
|
4114
|
-
passkeyUrl: yield this.getLoginUrl({ sessionId: sessionLookupId, shorten, portalTheme }),
|
|
4115
|
-
passkeyKnownDeviceUrl: yield this.constructPortalUrl("loginAuth", {
|
|
4116
|
-
sessionId: sessionLookupId,
|
|
4117
|
-
newDevice: {
|
|
4118
|
-
sessionId: sessionLookupId,
|
|
4119
|
-
encryptionKey: getPublicKeyHex(this.loginEncryptionKeyPair)
|
|
4120
|
-
},
|
|
4121
|
-
shorten,
|
|
4122
|
-
portalTheme
|
|
4123
|
-
})
|
|
4124
|
-
} : {}), isPasswordPossible ? {
|
|
4125
|
-
passwordUrl: yield this.constructPortalUrl("loginPassword", {
|
|
4126
|
-
sessionId: sessionLookupId,
|
|
4127
|
-
shorten,
|
|
4128
|
-
portalTheme,
|
|
4129
|
-
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4130
|
-
})
|
|
4131
|
-
} : {}), isPINPossible ? {
|
|
4132
|
-
pinUrl: yield this.constructPortalUrl("loginPIN", {
|
|
4133
|
-
sessionId: sessionLookupId,
|
|
4134
|
-
shorten,
|
|
4135
|
-
portalTheme,
|
|
4136
|
-
params: { isEmbedded: `${!loginState.isWalletSelectionNeeded}` }
|
|
4137
|
-
})
|
|
4138
|
-
} : {});
|
|
4139
|
-
});
|
|
4140
|
-
};
|
|
4141
|
-
prepareSignUpState_fn = function(_0, _1) {
|
|
4142
|
-
return __async(this, arguments, function* (serverSignupState, { useShortUrls: shorten = false, portalTheme }) {
|
|
4143
|
-
const _a = serverSignupState, { signupAuthMethods = [] } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
4144
|
-
const isPasskeySupported = yield this.isPasskeySupported();
|
|
4145
|
-
const [isPasskey, isPassword, isPIN] = [
|
|
4146
|
-
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
4147
|
-
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
4148
|
-
signupAuthMethods.includes(AuthMethod.PIN)
|
|
4149
|
-
];
|
|
4150
|
-
if (!isPasskey && !isPassword && !isPIN) {
|
|
4151
|
-
throw new Error(
|
|
4152
|
-
"No supported authentication methods found. Please ensure you have enabled either WebAuth passkeys, passwords or PINs in your Developer Portal settings."
|
|
4153
|
-
);
|
|
4154
|
-
}
|
|
4155
|
-
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
4156
|
-
isPasskeySupported,
|
|
4157
|
-
signupAuthMethods
|
|
4158
|
-
});
|
|
4159
|
-
if (isPasskey) {
|
|
4160
|
-
const { url: passkeyUrl, credentialId: passkeyId } = yield this.getNewCredentialAndUrl({
|
|
4161
|
-
authMethod: "PASSKEY",
|
|
4162
|
-
shorten
|
|
4163
2948
|
});
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
if (isPassword) {
|
|
4168
|
-
const { url: passwordUrl, credentialId: passwordId } = yield this.getNewCredentialAndUrl({
|
|
4169
|
-
authMethod: "PASSWORD",
|
|
4170
|
-
portalTheme,
|
|
4171
|
-
shorten
|
|
4172
|
-
});
|
|
4173
|
-
signupState.passwordUrl = passwordUrl;
|
|
4174
|
-
signupState.passwordId = passwordId;
|
|
2949
|
+
yield this.setWallets(this.wallets);
|
|
2950
|
+
} else {
|
|
2951
|
+
__privateGet(this, _walletService).wallets = {};
|
|
4175
2952
|
}
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
2953
|
+
__privateGet(this, _walletService).currentWalletIds = {};
|
|
2954
|
+
__privateGet(this, _externalWalletService).externalWallets = {};
|
|
2955
|
+
this.loginEncryptionKeyPair = void 0;
|
|
2956
|
+
__privateGet(this, _authService).authInfo = void 0;
|
|
2957
|
+
this.accountLinkInProgress = void 0;
|
|
2958
|
+
__privateGet(this, _authService).userId = void 0;
|
|
2959
|
+
__privateGet(this, _sessionManagementService).sessionCookie = void 0;
|
|
2960
|
+
this.isEnclaveUser = false;
|
|
2961
|
+
if (isSessionActive) {
|
|
2962
|
+
dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
|
|
2963
|
+
if (!skipStateReset) {
|
|
2964
|
+
__privateGet(this, _stateManager).send({ type: "LOGOUT" });
|
|
2965
|
+
}
|
|
4184
2966
|
}
|
|
4185
|
-
return signupState;
|
|
4186
2967
|
});
|
|
4187
2968
|
};
|
|
4188
2969
|
_ParaCore.version = constants.PARA_CORE_VERSION;
|