@getpara/core-sdk 2.12.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 +793 -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 +796 -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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__objRest,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "../chunk-7B52C2XE.js";
|
|
7
|
+
import { AuthMethod } from "@getpara/user-management-client";
|
|
8
|
+
import { BaseAuthFlowService } from "./BaseAuthFlowService.js";
|
|
9
|
+
import { ParaEvent } from "../types/index.js";
|
|
10
|
+
import { dispatchEvent } from "../utils/index.js";
|
|
11
|
+
import { extractErrorMessage } from "../utils/stateErrorHelpers.js";
|
|
12
|
+
import { waitForAuthStateChange, waitForCoreStateChange } from "../utils/stateListener.js";
|
|
13
|
+
class SignupFlowService extends BaseAuthFlowService {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.prepareState = (serverAuthState, opts) => __async(this, null, function* () {
|
|
17
|
+
yield this.setupAuthFromServerState(serverAuthState);
|
|
18
|
+
const _a = serverAuthState, { signupAuthMethods = [] } = _a, authState = __objRest(_a, ["signupAuthMethods"]);
|
|
19
|
+
const { useShortUrls: shorten = false, portalTheme } = opts;
|
|
20
|
+
const isPasskeySupported = yield this.paraCoreInterface.isPasskeySupported();
|
|
21
|
+
const [isPasskey, isPassword, isPIN] = [
|
|
22
|
+
signupAuthMethods.includes(AuthMethod.PASSKEY),
|
|
23
|
+
signupAuthMethods.includes(AuthMethod.PASSWORD) || !isPasskeySupported,
|
|
24
|
+
signupAuthMethods.includes(AuthMethod.PIN)
|
|
25
|
+
];
|
|
26
|
+
if (!isPasskey && !isPassword && !isPIN) {
|
|
27
|
+
throw new Error("No supported authentication methods found...");
|
|
28
|
+
}
|
|
29
|
+
const signupState = __spreadProps(__spreadValues({}, authState), {
|
|
30
|
+
isPasskeySupported,
|
|
31
|
+
signupAuthMethods
|
|
32
|
+
});
|
|
33
|
+
if (isPasskey) {
|
|
34
|
+
const { url: passkeyUrl, credentialId: passkeyId } = yield this.services.authService.getNewCredentialAndUrl({
|
|
35
|
+
authMethod: "PASSKEY",
|
|
36
|
+
shorten
|
|
37
|
+
});
|
|
38
|
+
if (passkeyUrl) signupState.passkeyUrl = passkeyUrl;
|
|
39
|
+
signupState.passkeyId = passkeyId;
|
|
40
|
+
}
|
|
41
|
+
if (isPassword) {
|
|
42
|
+
const { url: passwordUrl, credentialId: passwordId } = yield this.services.authService.getNewCredentialAndUrl({
|
|
43
|
+
authMethod: "PASSWORD",
|
|
44
|
+
portalTheme,
|
|
45
|
+
shorten
|
|
46
|
+
});
|
|
47
|
+
signupState.passwordUrl = passwordUrl;
|
|
48
|
+
signupState.passwordId = passwordId;
|
|
49
|
+
}
|
|
50
|
+
if (isPIN) {
|
|
51
|
+
const { url: pinUrl, credentialId: pinId } = yield this.services.authService.getNewCredentialAndUrl({
|
|
52
|
+
authMethod: "PIN",
|
|
53
|
+
portalTheme,
|
|
54
|
+
shorten
|
|
55
|
+
});
|
|
56
|
+
signupState.pinUrl = pinUrl;
|
|
57
|
+
signupState.pinId = pinId;
|
|
58
|
+
}
|
|
59
|
+
return signupState;
|
|
60
|
+
});
|
|
61
|
+
this.waitForSignup = (_0) => __async(this, [_0], function* ({ isCanceled = () => false, onCancel, onPoll }) {
|
|
62
|
+
this.stateManager.send({
|
|
63
|
+
type: "WAIT_FOR_SESSION",
|
|
64
|
+
data: {
|
|
65
|
+
onCancel,
|
|
66
|
+
onPoll,
|
|
67
|
+
isCanceled
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return yield waitForAuthStateChange({
|
|
71
|
+
stateManager: this.stateManager,
|
|
72
|
+
resolvePhases: [
|
|
73
|
+
{
|
|
74
|
+
phase: "authenticated",
|
|
75
|
+
onPhase: () => {
|
|
76
|
+
dispatchEvent(ParaEvent.ACCOUNT_CREATION_EVENT, true);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
onReject: (state) => {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = dispatchEvent) == null ? void 0 : _a(ParaEvent.ACCOUNT_CREATION_EVENT, {}, extractErrorMessage(state.error, "failed to sign up user"));
|
|
84
|
+
},
|
|
85
|
+
waitForCoreAuthenticated: false
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
this.waitForWalletCreation = (..._0) => __async(this, [..._0], function* ({ isCanceled = () => false, onCancel, onPoll } = {}) {
|
|
89
|
+
this.stateManager.send({
|
|
90
|
+
type: "WAIT_FOR_WALLET_CREATION",
|
|
91
|
+
data: {
|
|
92
|
+
onCancel,
|
|
93
|
+
onPoll,
|
|
94
|
+
isCanceled
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return yield waitForCoreStateChange({
|
|
98
|
+
stateManager: this.stateManager,
|
|
99
|
+
resolvePhases: [
|
|
100
|
+
{
|
|
101
|
+
phase: "authenticated",
|
|
102
|
+
onPhase: (state) => {
|
|
103
|
+
const resp = state.newWalletsResult;
|
|
104
|
+
dispatchEvent(ParaEvent.ACCOUNT_SETUP_EVENT, resp);
|
|
105
|
+
return resp;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
onReject: (state) => {
|
|
110
|
+
var _a;
|
|
111
|
+
(_a = dispatchEvent) == null ? void 0 : _a(ParaEvent.ACCOUNT_SETUP_EVENT, {}, extractErrorMessage(state.error, "failed to sign up user"));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
SignupFlowService
|
|
119
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__objRest,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../chunk-7B52C2XE.js";
|
|
6
|
+
import { AuthMethod } from "@getpara/user-management-client";
|
|
7
|
+
import { BaseAuthFlowService } from "./BaseAuthFlowService.js";
|
|
8
|
+
import { LOCAL_STORAGE_IS_ENCLAVE_USER } from "../constants.js";
|
|
9
|
+
import { waitForAuthStateChange } from "../utils/stateListener.js";
|
|
10
|
+
class VerificationFlowService extends BaseAuthFlowService {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.prepareState = (serverAuthState, opts) => __async(this, null, function* () {
|
|
14
|
+
var _a;
|
|
15
|
+
yield this.setupAuthFromServerState(serverAuthState);
|
|
16
|
+
const { useShortUrls: shorten = false, portalTheme, sessionLookupId } = opts;
|
|
17
|
+
let isSLOPossible = false;
|
|
18
|
+
if (serverAuthState.nextStage === "login") {
|
|
19
|
+
isSLOPossible = serverAuthState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
20
|
+
} else if (serverAuthState.nextStage === "signup") {
|
|
21
|
+
isSLOPossible = serverAuthState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
|
|
22
|
+
}
|
|
23
|
+
this.services.authService.isEnclaveUser = isSLOPossible;
|
|
24
|
+
yield this.paraCoreInterface.localStorageSetItem(LOCAL_STORAGE_IS_ENCLAVE_USER, JSON.stringify(isSLOPossible));
|
|
25
|
+
const isExternalWalletFullAuth = (_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth;
|
|
26
|
+
return __spreadValues(__spreadValues({}, serverAuthState), isSLOPossible || isExternalWalletFullAuth ? {
|
|
27
|
+
loginUrl: yield this.services.portalUrlService.getLoginUrl({
|
|
28
|
+
authMethod: AuthMethod.BASIC_LOGIN,
|
|
29
|
+
sessionId: sessionLookupId,
|
|
30
|
+
shorten,
|
|
31
|
+
portalTheme
|
|
32
|
+
})
|
|
33
|
+
} : {});
|
|
34
|
+
});
|
|
35
|
+
this.performVerifyNewAccount = (params) => __async(this, null, function* () {
|
|
36
|
+
this.services.authService.assertIsAuthSet(["email", "phone"]);
|
|
37
|
+
const _a = params, { verificationCode } = _a, urlOptions = __objRest(_a, ["verificationCode"]);
|
|
38
|
+
const serverAuthState = yield this.paraCoreInterface.ctx.client.verifyAccount(this.services.authService.userId, {
|
|
39
|
+
verificationCode
|
|
40
|
+
});
|
|
41
|
+
if (serverAuthState.stage === "login" || serverAuthState.stage === "done") {
|
|
42
|
+
throw new Error("Account already exists.");
|
|
43
|
+
}
|
|
44
|
+
yield this.services.sessionManagementService.touchSession(true);
|
|
45
|
+
return { authState: serverAuthState, opts: urlOptions };
|
|
46
|
+
});
|
|
47
|
+
this.verifyNewAccount = (params) => __async(this, null, function* () {
|
|
48
|
+
this.stateManager.send({ type: "VERIFY_NEW_ACCOUNT", data: params });
|
|
49
|
+
return yield waitForAuthStateChange({
|
|
50
|
+
stateManager: this.stateManager,
|
|
51
|
+
resolvePhases: [{ phase: "awaiting_session_start", onPhase: (state) => state.authStateResult }]
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
this.performVerifyExternalWallet = (params) => __async(this, null, function* () {
|
|
55
|
+
var _a;
|
|
56
|
+
let serverAuthState;
|
|
57
|
+
let urlOptions;
|
|
58
|
+
if ("serverAuthState" in params && params.serverAuthState !== void 0) {
|
|
59
|
+
serverAuthState = params.serverAuthState;
|
|
60
|
+
} else if ("externalWallet" in params) {
|
|
61
|
+
let signedMessage = params.signedMessage, cosmosPublicKeyHex = params.cosmosPublicKeyHex, cosmosSigner = params.cosmosSigner;
|
|
62
|
+
const { externalWallet, signatureVerificationMessage, portalTheme, useShortUrls } = params;
|
|
63
|
+
if (!signedMessage && !signatureVerificationMessage) {
|
|
64
|
+
throw new Error("One of signedMessage or signatureVerificationMessage is required for verifying external wallet");
|
|
65
|
+
}
|
|
66
|
+
if (!signedMessage) {
|
|
67
|
+
const signResponse = yield this.services.externalWalletService.signMessage({
|
|
68
|
+
type: externalWallet.type,
|
|
69
|
+
address: externalWallet.address,
|
|
70
|
+
message: signatureVerificationMessage
|
|
71
|
+
});
|
|
72
|
+
signedMessage = signResponse.signature;
|
|
73
|
+
cosmosPublicKeyHex = signResponse.cosmosPublicKeyHex;
|
|
74
|
+
cosmosSigner = signResponse.cosmosSigner;
|
|
75
|
+
}
|
|
76
|
+
const _serverAuthState = yield this.paraCoreInterface.ctx.client.verifyExternalWallet(
|
|
77
|
+
this.services.authService.userId,
|
|
78
|
+
{
|
|
79
|
+
externalWallet,
|
|
80
|
+
signedMessage,
|
|
81
|
+
cosmosPublicKeyHex,
|
|
82
|
+
cosmosSigner
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
serverAuthState = _serverAuthState;
|
|
86
|
+
urlOptions = { portalTheme, useShortUrls };
|
|
87
|
+
}
|
|
88
|
+
let sessionLookupId;
|
|
89
|
+
if (serverAuthState.stage === "login" && ((_a = serverAuthState.loginAuthMethods) == null ? void 0 : _a.includes(AuthMethod.PIN))) {
|
|
90
|
+
sessionLookupId = (yield this.services.sessionManagementService.touchSession()).sessionLookupId;
|
|
91
|
+
}
|
|
92
|
+
return { authState: serverAuthState, opts: __spreadValues({}, urlOptions), sessionLookupId };
|
|
93
|
+
});
|
|
94
|
+
this.verifyExternalWallet = (params) => __async(this, null, function* () {
|
|
95
|
+
this.stateManager.send({ type: "VERIFY_EXTERNAL_WALLET", data: params });
|
|
96
|
+
return yield waitForAuthStateChange({
|
|
97
|
+
stateManager: this.stateManager,
|
|
98
|
+
resolvePhases: [
|
|
99
|
+
{
|
|
100
|
+
phase: "awaiting_session_start",
|
|
101
|
+
onPhase: (state) => state.authStateResult
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
phase: "authenticated",
|
|
105
|
+
onPhase: (state) => state.authStateResult
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
this.retryVerifyExternalWallet = () => __async(this, null, function* () {
|
|
111
|
+
this.stateManager.send({ type: "VERIFY_EXTERNAL_WALLET" });
|
|
112
|
+
return yield waitForAuthStateChange({
|
|
113
|
+
stateManager: this.stateManager,
|
|
114
|
+
resolvePhases: [
|
|
115
|
+
{
|
|
116
|
+
phase: "awaiting_wallet_verification",
|
|
117
|
+
onPhase: (state) => state.authStateResult
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
phase: "awaiting_session_start",
|
|
121
|
+
onPhase: (state) => state.authStateResult
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
phase: "authenticated",
|
|
125
|
+
onPhase: (state) => state.authStateResult
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
this.performVerifyTelegram = (_a) => __async(this, null, function* () {
|
|
131
|
+
var _b = _a, {
|
|
132
|
+
serverAuthState: optsServerAuthState,
|
|
133
|
+
telegramAuthResponse
|
|
134
|
+
} = _b, urlOptions = __objRest(_b, [
|
|
135
|
+
"serverAuthState",
|
|
136
|
+
"telegramAuthResponse"
|
|
137
|
+
]);
|
|
138
|
+
if (!optsServerAuthState && !telegramAuthResponse) {
|
|
139
|
+
throw new Error("one of serverAuthState or telegramAuthResponse are required for verifying telegram");
|
|
140
|
+
}
|
|
141
|
+
const serverAuthState = optsServerAuthState != null ? optsServerAuthState : yield this.paraCoreInterface.ctx.client.verifyTelegram({ authObject: telegramAuthResponse });
|
|
142
|
+
const { sessionLookupId } = yield this.services.sessionManagementService.touchSession();
|
|
143
|
+
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
144
|
+
});
|
|
145
|
+
this.verifyTelegram = (params) => __async(this, null, function* () {
|
|
146
|
+
this.stateManager.send({ type: "AUTHENTICATE_TELEGRAM_LEGACY", data: params });
|
|
147
|
+
return yield waitForAuthStateChange({
|
|
148
|
+
stateManager: this.stateManager,
|
|
149
|
+
resolvePhases: [
|
|
150
|
+
{
|
|
151
|
+
phase: "awaiting_session_start",
|
|
152
|
+
onPhase: (state) => state.authStateResult
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
this.performVerifyFarcaster = (_c) => __async(this, null, function* () {
|
|
158
|
+
var _d = _c, { serverAuthState } = _d, urlOptions = __objRest(_d, ["serverAuthState"]);
|
|
159
|
+
const { sessionLookupId } = yield this.services.sessionManagementService.touchSession();
|
|
160
|
+
return { authState: serverAuthState, opts: urlOptions, sessionLookupId };
|
|
161
|
+
});
|
|
162
|
+
this.verifyFarcaster = (params) => __async(this, null, function* () {
|
|
163
|
+
this.stateManager.send({ type: "AUTHENTICATE_FARCASTER_LEGACY", data: params });
|
|
164
|
+
return yield waitForAuthStateChange({
|
|
165
|
+
stateManager: this.stateManager,
|
|
166
|
+
resolvePhases: [
|
|
167
|
+
{
|
|
168
|
+
phase: "awaiting_session_start",
|
|
169
|
+
onPhase: (state) => state.authStateResult
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
VerificationFlowService
|
|
178
|
+
};
|