@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../chunk-7B52C2XE.js";
|
|
5
|
+
import { extractAuthInfo } from "@getpara/user-management-client";
|
|
6
|
+
class BaseAuthFlowService {
|
|
7
|
+
constructor(paraCoreInterface, stateManager, services) {
|
|
8
|
+
this.paraCoreInterface = paraCoreInterface;
|
|
9
|
+
this.stateManager = stateManager;
|
|
10
|
+
this.services = services;
|
|
11
|
+
// Shared auth setup from server state
|
|
12
|
+
this.setupAuthFromServerState = (serverAuthState) => __async(this, null, function* () {
|
|
13
|
+
const { auth, userId, displayName, pfpUrl, username, externalWallet } = serverAuthState;
|
|
14
|
+
const authInfo = __spreadValues(__spreadValues({}, extractAuthInfo(auth, { isRequired: true })), Object.fromEntries(Object.entries({ displayName, pfpUrl, username, externalWallet }).filter(([_, v]) => !!v)));
|
|
15
|
+
yield this.services.authService.setAuthInfo(authInfo);
|
|
16
|
+
this.services.authService.assertIsAuthSet();
|
|
17
|
+
if (userId) {
|
|
18
|
+
yield this.services.authService.setUserId(userId);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
BaseAuthFlowService
|
|
25
|
+
};
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async,
|
|
3
|
+
__privateAdd,
|
|
4
|
+
__privateGet,
|
|
5
|
+
__privateSet,
|
|
6
|
+
__spreadProps,
|
|
7
|
+
__spreadValues
|
|
8
|
+
} from "../chunk-7B52C2XE.js";
|
|
9
|
+
var _stateManager, _authService, _walletService, _paraCoreInterface, _externalWallets, _watchedProviders, _onWalletDisconnected;
|
|
10
|
+
import { ParaEvent } from "../types/events.js";
|
|
11
|
+
import { LOCAL_STORAGE_EXTERNAL_WALLETS } from "../constants.js";
|
|
12
|
+
import { dispatchEvent } from "../utils/index.js";
|
|
13
|
+
class ExternalWalletService {
|
|
14
|
+
constructor(paraCore) {
|
|
15
|
+
__privateAdd(this, _stateManager);
|
|
16
|
+
__privateAdd(this, _authService);
|
|
17
|
+
__privateAdd(this, _walletService);
|
|
18
|
+
__privateAdd(this, _paraCoreInterface);
|
|
19
|
+
__privateAdd(this, _externalWallets, {});
|
|
20
|
+
__privateAdd(this, _watchedProviders, /* @__PURE__ */ new Set());
|
|
21
|
+
this.externalWalletProviderInterfaces = {};
|
|
22
|
+
this.init = ({
|
|
23
|
+
authService,
|
|
24
|
+
walletService,
|
|
25
|
+
stateManager
|
|
26
|
+
}) => {
|
|
27
|
+
__privateSet(this, _walletService, walletService);
|
|
28
|
+
__privateSet(this, _authService, authService);
|
|
29
|
+
__privateSet(this, _stateManager, stateManager);
|
|
30
|
+
};
|
|
31
|
+
this.initExternalWalletProvider = (_0) => __async(this, [_0], function* ({ type, interface: providerInterface }) {
|
|
32
|
+
this.externalWalletProviderInterfaces[type] = providerInterface;
|
|
33
|
+
});
|
|
34
|
+
this.waitForProvidersLoading = () => __async(this, null, function* () {
|
|
35
|
+
const storedWalletTypes = new Set(Object.values(this.externalWallets).map((wallet) => wallet.type));
|
|
36
|
+
if (storedWalletTypes.size === 0) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
for (let i = 0; i < 20; i++) {
|
|
40
|
+
const neededProviderInterfaces = Array.from(storedWalletTypes).map((type) => ({
|
|
41
|
+
type,
|
|
42
|
+
interface: this.externalWalletProviderInterfaces[type]
|
|
43
|
+
})).filter(({ interface: providerInterface }) => !!providerInterface);
|
|
44
|
+
if (neededProviderInterfaces.length !== storedWalletTypes.size) {
|
|
45
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const loadingResults = yield Promise.all(
|
|
49
|
+
neededProviderInterfaces.map((_0) => __async(this, [_0], function* ({ type, interface: providerInterface }) {
|
|
50
|
+
try {
|
|
51
|
+
const providerAddresses = yield providerInterface.getAddress();
|
|
52
|
+
const storedAddressesForType = Object.values(this.externalWallets).filter((wallet) => wallet.type === type).map((wallet) => Object.keys(this.externalWallets).find((addr) => this.externalWallets[addr] === wallet)).filter(Boolean);
|
|
53
|
+
const allAddressesAvailable = storedAddressesForType.every((addr) => providerAddresses.includes(addr));
|
|
54
|
+
return allAddressesAvailable;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.warn(`Error checking provider ${type}:`, error);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}))
|
|
60
|
+
);
|
|
61
|
+
if (loadingResults.every((result) => result === true)) {
|
|
62
|
+
neededProviderInterfaces.forEach(({ type, interface: providerInterface }) => {
|
|
63
|
+
if (!__privateGet(this, _watchedProviders).has(type)) {
|
|
64
|
+
__privateGet(this, _watchedProviders).add(type);
|
|
65
|
+
providerInterface.watchDisconnection(() => __async(this, null, function* () {
|
|
66
|
+
yield __privateGet(this, _onWalletDisconnected).call(this);
|
|
67
|
+
}));
|
|
68
|
+
providerInterface.watchWalletChange((params) => __async(this, null, function* () {
|
|
69
|
+
yield this.switchExternalWallet(params);
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
this.assertValidConnection = () => __async(this, null, function* () {
|
|
80
|
+
if (__privateGet(this, _stateManager).getSnapshot().authStatePhase === "switching_external_wallet") {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (this.externalWalletConnectionType === "NONE") {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const connectedAddresses = (yield Promise.all(
|
|
87
|
+
Object.values(this.externalWalletProviderInterfaces).map((providerInterface) => __async(this, null, function* () {
|
|
88
|
+
return yield providerInterface.getAddress();
|
|
89
|
+
}))
|
|
90
|
+
)).filter((a) => !!a);
|
|
91
|
+
const storedExternalWalletAddresses = Object.keys(this.externalWallets);
|
|
92
|
+
const someConnectedHaveStoredWallets = connectedAddresses.some(
|
|
93
|
+
(connectedAddress) => connectedAddress && this.externalWallets[connectedAddress]
|
|
94
|
+
);
|
|
95
|
+
const allStoredWalletsAreConnected = storedExternalWalletAddresses.every(
|
|
96
|
+
(storedAddress) => connectedAddresses.includes(storedAddress)
|
|
97
|
+
);
|
|
98
|
+
const validConnection = someConnectedHaveStoredWallets && allStoredWalletsAreConnected;
|
|
99
|
+
if (!validConnection) {
|
|
100
|
+
yield __privateGet(this, _paraCoreInterface).logout();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Function to perform signing a message with an external wallet
|
|
105
|
+
*/
|
|
106
|
+
this.signMessage = (_0) => __async(this, [_0], function* ({ type, message, address }) {
|
|
107
|
+
const providerInterface = this.externalWalletProviderInterfaces[type];
|
|
108
|
+
if (!providerInterface) {
|
|
109
|
+
throw new Error(`External wallet provider interface for type ${type} is not initialized.`);
|
|
110
|
+
}
|
|
111
|
+
const signature = yield providerInterface.signMessage({ message, address });
|
|
112
|
+
return __spreadValues({ address }, signature);
|
|
113
|
+
});
|
|
114
|
+
this.connectParaConnectors = () => __async(this, null, function* () {
|
|
115
|
+
const types = Array.from(new Set(Object.values(__privateGet(this, _walletService).wallets).map((w) => w.type)));
|
|
116
|
+
for (const type of types) {
|
|
117
|
+
const providerInterface = this.externalWalletProviderInterfaces[type];
|
|
118
|
+
if (!providerInterface) {
|
|
119
|
+
console.error(
|
|
120
|
+
`External wallet provider interface for type ${type} is not initialized. Para connector will not be connected.`
|
|
121
|
+
);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
yield providerInterface.connectParaConnector();
|
|
126
|
+
} catch (e) {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
this.performSwitchExternalWallet = (params) => __async(this, null, function* () {
|
|
131
|
+
if (this.externalWalletConnectionType !== "CONNECTION_ONLY") {
|
|
132
|
+
throw new Error("Cannot switch external wallets when using Para authentication or wallet verification.");
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const partner = yield __privateGet(this, _paraCoreInterface).assertPartner();
|
|
136
|
+
const loginResp = yield __privateGet(this, _authService).performLoginExternalWallet({
|
|
137
|
+
externalWallet: __spreadProps(__spreadValues({}, params.externalWallet), {
|
|
138
|
+
partnerId: partner.id,
|
|
139
|
+
withFullParaAuth: false,
|
|
140
|
+
withVerification: false
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
if (loginResp.authState.stage !== "done" && loginResp.authState.stage !== "verify") {
|
|
144
|
+
throw new Error("External wallet switch did not complete successfully.");
|
|
145
|
+
}
|
|
146
|
+
yield this.setExternalWallet({ externalWallet: [loginResp.authState.externalWallet] });
|
|
147
|
+
return { externalWallet: loginResp.authState.externalWallet };
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Error during external wallet switch login:", error);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
this.switchExternalWallet = (params) => __async(this, null, function* () {
|
|
154
|
+
if (__privateGet(this, _externalWallets)[params.externalWallet.address]) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
__privateGet(this, _stateManager).send({ type: "SWITCH_EXTERNAL_WALLET", data: params });
|
|
158
|
+
});
|
|
159
|
+
__privateAdd(this, _onWalletDisconnected, () => __async(this, null, function* () {
|
|
160
|
+
if (this.externalWalletConnectionType === "NONE") {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
yield __privateGet(this, _paraCoreInterface).logout();
|
|
164
|
+
}));
|
|
165
|
+
/**
|
|
166
|
+
* Function to perform connecting an external wallet
|
|
167
|
+
*/
|
|
168
|
+
this.performConnectExternalWallet = (_0) => __async(this, [_0], function* ({ connect }) {
|
|
169
|
+
const connectResp = yield connect();
|
|
170
|
+
const providerInterface = this.externalWalletProviderInterfaces[connectResp.externalWallet.type];
|
|
171
|
+
if (!providerInterface) {
|
|
172
|
+
throw new Error(`External wallet provider interface for type ${connectResp.externalWallet.type} is not initialized.`);
|
|
173
|
+
}
|
|
174
|
+
if (!__privateGet(this, _watchedProviders).has(connectResp.externalWallet.type)) {
|
|
175
|
+
__privateGet(this, _watchedProviders).add(connectResp.externalWallet.type);
|
|
176
|
+
providerInterface.watchDisconnection(() => __async(this, null, function* () {
|
|
177
|
+
yield __privateGet(this, _onWalletDisconnected).call(this);
|
|
178
|
+
}));
|
|
179
|
+
providerInterface.watchWalletChange((params) => __async(this, null, function* () {
|
|
180
|
+
yield this.switchExternalWallet(params);
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
return connectResp;
|
|
184
|
+
});
|
|
185
|
+
this.disconnectExternalWallet = (type) => __async(this, null, function* () {
|
|
186
|
+
const providerInterface = this.externalWalletProviderInterfaces[type];
|
|
187
|
+
if (!providerInterface) {
|
|
188
|
+
throw new Error(`External wallet provider interface for type ${type} is not initialized.`);
|
|
189
|
+
}
|
|
190
|
+
return yield providerInterface.disconnect();
|
|
191
|
+
});
|
|
192
|
+
this.disconnectAllExternalWallets = () => __async(this, null, function* () {
|
|
193
|
+
const disconnectPromises = Object.values(this.externalWalletProviderInterfaces).map(
|
|
194
|
+
(providerInterface) => providerInterface.disconnect()
|
|
195
|
+
);
|
|
196
|
+
yield Promise.all(disconnectPromises);
|
|
197
|
+
__privateGet(this, _watchedProviders).clear();
|
|
198
|
+
});
|
|
199
|
+
this.setExternalWallet = (_0) => __async(this, [_0], function* ({ externalWallet }) {
|
|
200
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateGet(this, _paraCoreInterface).assertPartner();
|
|
201
|
+
this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
|
|
202
|
+
(acc, {
|
|
203
|
+
partnerId: wPartnerId,
|
|
204
|
+
address,
|
|
205
|
+
type,
|
|
206
|
+
provider,
|
|
207
|
+
providerId,
|
|
208
|
+
addressBech32,
|
|
209
|
+
withFullParaAuth,
|
|
210
|
+
isConnectionOnly,
|
|
211
|
+
withVerification
|
|
212
|
+
}) => {
|
|
213
|
+
if (partnerId === wPartnerId && supportedWalletTypes.some(({ type: supportedType }) => supportedType === type)) {
|
|
214
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
215
|
+
[address]: {
|
|
216
|
+
id: address,
|
|
217
|
+
partnerId,
|
|
218
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
219
|
+
type,
|
|
220
|
+
name: provider,
|
|
221
|
+
isExternal: true,
|
|
222
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
223
|
+
externalProviderId: providerId,
|
|
224
|
+
signer: "",
|
|
225
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
226
|
+
isExternalWithVerification: withVerification
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
if (partnerId !== wPartnerId) {
|
|
231
|
+
throw new Error(`Partner ID on the wallet does not match the current partner.`);
|
|
232
|
+
}
|
|
233
|
+
console.warn(
|
|
234
|
+
`External wallet with address ${address} and type ${type} is not supported by the current partner, skipping this wallet. Supported wallet types are: ${supportedWalletTypes.map(({ type: supportedType }) => supportedType).join(", ")}`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
return acc;
|
|
238
|
+
},
|
|
239
|
+
{}
|
|
240
|
+
);
|
|
241
|
+
yield this.setExternalWallets({ externalWallets: this.externalWallets });
|
|
242
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
243
|
+
});
|
|
244
|
+
this.setExternalWallets = (_0) => __async(this, [_0], function* ({ externalWallets }) {
|
|
245
|
+
if (typeof externalWallets === "function") {
|
|
246
|
+
this.externalWallets = externalWallets(this.externalWallets);
|
|
247
|
+
} else {
|
|
248
|
+
this.externalWallets = externalWallets;
|
|
249
|
+
}
|
|
250
|
+
yield __privateGet(this, _paraCoreInterface).localStorageSetItem(LOCAL_STORAGE_EXTERNAL_WALLETS, JSON.stringify(this.externalWallets));
|
|
251
|
+
});
|
|
252
|
+
this.addExternalWallets = (_0) => __async(this, [_0], function* ({ externalWallets }) {
|
|
253
|
+
const { id: partnerId, supportedWalletTypes } = yield __privateGet(this, _paraCoreInterface).assertPartner();
|
|
254
|
+
this.externalWallets = __spreadValues(__spreadValues({}, Object.entries(this.externalWallets).reduce((acc, [address, wallet]) => {
|
|
255
|
+
if (partnerId === wallet.partnerId && supportedWalletTypes.some(({ type }) => type === wallet.type)) {
|
|
256
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
257
|
+
[address]: wallet
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return acc;
|
|
261
|
+
}, {})), externalWallets.reduce(
|
|
262
|
+
(acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
|
|
263
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
264
|
+
[address]: {
|
|
265
|
+
id: address,
|
|
266
|
+
partnerId,
|
|
267
|
+
address: addressBech32 != null ? addressBech32 : address,
|
|
268
|
+
type,
|
|
269
|
+
name: provider,
|
|
270
|
+
isExternal: true,
|
|
271
|
+
isExternalWithParaAuth: withFullParaAuth,
|
|
272
|
+
externalProviderId: providerId,
|
|
273
|
+
signer: "",
|
|
274
|
+
isExternalConnectionOnly: isConnectionOnly,
|
|
275
|
+
isExternalWithVerification: withVerification
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
{}
|
|
280
|
+
));
|
|
281
|
+
this.setExternalWallets({ externalWallets: this.externalWallets });
|
|
282
|
+
dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
|
|
283
|
+
});
|
|
284
|
+
__privateSet(this, _paraCoreInterface, paraCore.getExternalWalletServiceInterface());
|
|
285
|
+
}
|
|
286
|
+
get externalWalletWithParaAuth() {
|
|
287
|
+
const externalWallets = Object.values(this.externalWallets);
|
|
288
|
+
return externalWallets.find((w) => w.isExternalWithParaAuth);
|
|
289
|
+
}
|
|
290
|
+
get externalWallets() {
|
|
291
|
+
return __privateGet(this, _externalWallets);
|
|
292
|
+
}
|
|
293
|
+
set externalWallets(value) {
|
|
294
|
+
__privateSet(this, _externalWallets, value);
|
|
295
|
+
}
|
|
296
|
+
get externalWalletConnectionType() {
|
|
297
|
+
var _a, _b, _c;
|
|
298
|
+
if ((_a = __privateGet(this, _authService)) == null ? void 0 : _a.isExternalWalletAuth) {
|
|
299
|
+
return "AUTHENTICATED";
|
|
300
|
+
} else if ((_b = __privateGet(this, _authService)) == null ? void 0 : _b.isExternalWalletWithVerification) {
|
|
301
|
+
return "VERIFICATION";
|
|
302
|
+
} else if (!!Object.keys(this.externalWallets).length) {
|
|
303
|
+
const hasEmbeddedWallets = Object.keys((_c = __privateGet(this, _walletService)) == null ? void 0 : _c.wallets).some(
|
|
304
|
+
(id) => {
|
|
305
|
+
var _a2;
|
|
306
|
+
return !((_a2 = __privateGet(this, _walletService)) == null ? void 0 : _a2.wallets[id].isExternal);
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
if (hasEmbeddedWallets) {
|
|
310
|
+
return "NONE";
|
|
311
|
+
} else {
|
|
312
|
+
return "CONNECTION_ONLY";
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return "NONE";
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
_stateManager = new WeakMap();
|
|
319
|
+
_authService = new WeakMap();
|
|
320
|
+
_walletService = new WeakMap();
|
|
321
|
+
_paraCoreInterface = new WeakMap();
|
|
322
|
+
_externalWallets = new WeakMap();
|
|
323
|
+
_watchedProviders = new WeakMap();
|
|
324
|
+
_onWalletDisconnected = new WeakMap();
|
|
325
|
+
export {
|
|
326
|
+
ExternalWalletService
|
|
327
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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 { getPublicKeyHex } from "../cryptography/utils.js";
|
|
10
|
+
import { ParaEvent } from "../types/events.js";
|
|
11
|
+
import { dispatchEvent } from "../utils/index.js";
|
|
12
|
+
import { waitForAuthStateChange } from "../utils/stateListener.js";
|
|
13
|
+
class LoginFlowService extends BaseAuthFlowService {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.prepareState = (serverAuthState, opts) => __async(this, null, function* () {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!opts.sessionLookupId && (!serverAuthState.externalWallet || !(((_a = serverAuthState.externalWallet) == null ? void 0 : _a.withFullParaAuth) && ((_b = serverAuthState.loginAuthMethods) == null ? void 0 : _b.includes(AuthMethod.PIN))))) {
|
|
19
|
+
opts.sessionLookupId = yield this.services.authService.prepareLogin();
|
|
20
|
+
}
|
|
21
|
+
yield this.setupAuthFromServerState(serverAuthState);
|
|
22
|
+
const _c = serverAuthState, { loginAuthMethods = [], hasPasswordWithoutPIN } = _c, authState = __objRest(_c, ["loginAuthMethods", "hasPasswordWithoutPIN"]);
|
|
23
|
+
const { useShortUrls: shorten = false, portalTheme, sessionLookupId } = opts;
|
|
24
|
+
const isPasskeySupported = yield this.paraCoreInterface.isPasskeySupported();
|
|
25
|
+
const isPasskeyPossible = loginAuthMethods.includes(AuthMethod.PASSKEY) && !this.paraCoreInterface.isNativePasskey;
|
|
26
|
+
const isPasswordPossible = loginAuthMethods.includes(AuthMethod.PASSWORD) && hasPasswordWithoutPIN;
|
|
27
|
+
const isPINPossible = loginAuthMethods.includes(AuthMethod.PIN);
|
|
28
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues({}, authState), {
|
|
29
|
+
isPasskeySupported,
|
|
30
|
+
loginAuthMethods
|
|
31
|
+
}), isPasskeyPossible ? {
|
|
32
|
+
passkeyUrl: yield this.services.portalUrlService.getLoginUrl({
|
|
33
|
+
sessionId: sessionLookupId,
|
|
34
|
+
shorten,
|
|
35
|
+
portalTheme
|
|
36
|
+
}),
|
|
37
|
+
passkeyKnownDeviceUrl: yield this.services.portalUrlService.constructPortalUrl("loginAuth", {
|
|
38
|
+
sessionId: sessionLookupId,
|
|
39
|
+
newDevice: {
|
|
40
|
+
sessionId: sessionLookupId,
|
|
41
|
+
encryptionKey: getPublicKeyHex(this.paraCoreInterface.loginEncryptionKeyPair)
|
|
42
|
+
},
|
|
43
|
+
shorten,
|
|
44
|
+
portalTheme
|
|
45
|
+
})
|
|
46
|
+
} : {}), isPasswordPossible ? {
|
|
47
|
+
passwordUrl: yield this.services.portalUrlService.constructPortalUrl("loginPassword", {
|
|
48
|
+
sessionId: sessionLookupId,
|
|
49
|
+
shorten,
|
|
50
|
+
portalTheme,
|
|
51
|
+
params: { isEmbedded: `${!serverAuthState.isWalletSelectionNeeded}` }
|
|
52
|
+
})
|
|
53
|
+
} : {}), isPINPossible ? {
|
|
54
|
+
pinUrl: yield this.services.portalUrlService.constructPortalUrl("loginPIN", {
|
|
55
|
+
sessionId: sessionLookupId,
|
|
56
|
+
shorten,
|
|
57
|
+
portalTheme,
|
|
58
|
+
params: { isEmbedded: `${!serverAuthState.isWalletSelectionNeeded}` }
|
|
59
|
+
})
|
|
60
|
+
} : {});
|
|
61
|
+
});
|
|
62
|
+
this.waitForLogin = (params) => __async(this, null, function* () {
|
|
63
|
+
this.stateManager.send({
|
|
64
|
+
type: "WAIT_FOR_SESSION",
|
|
65
|
+
data: __spreadValues({}, params)
|
|
66
|
+
});
|
|
67
|
+
return yield waitForAuthStateChange({
|
|
68
|
+
stateManager: this.stateManager,
|
|
69
|
+
resolvePhases: [
|
|
70
|
+
{
|
|
71
|
+
phase: "authenticated",
|
|
72
|
+
onPhase: () => {
|
|
73
|
+
const needsWallet = this.stateManager.getSnapshot().needsWallet;
|
|
74
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, true);
|
|
75
|
+
return {
|
|
76
|
+
partnerId: this.paraCoreInterface.partnerId,
|
|
77
|
+
needsWallet: needsWallet || Object.values(this.services.walletService.wallets).length === 0
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
rejectPhases: [
|
|
83
|
+
{
|
|
84
|
+
phase: "unauthenticated",
|
|
85
|
+
onPhase: () => new Error("canceled")
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
onReject: () => {
|
|
89
|
+
dispatchEvent(ParaEvent.LOGIN_EVENT, { isComplete: false }, "failed to setup user");
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
LoginFlowService
|
|
97
|
+
};
|