@block-auth.io/core 0.10.0 → 0.11.1
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/index.cjs +111 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -7
- package/dist/index.d.ts +19 -7
- package/dist/index.js +111 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -137,9 +137,11 @@ declare class WsClient {
|
|
|
137
137
|
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
138
138
|
* No-op if there is no open connection yet (connect() will pick up a
|
|
139
139
|
* ticket on its own once one exists).
|
|
140
|
-
* @returns
|
|
140
|
+
* @returns 'renewed' when a ticket was sent, 'refused' when the API answered
|
|
141
|
+
* 401 (no session behind the cookie), 'unavailable' otherwise (not
|
|
142
|
+
* connected yet, or a transient failure).
|
|
141
143
|
*/
|
|
142
|
-
refreshAuth(): Promise<
|
|
144
|
+
refreshAuth(): Promise<'renewed' | 'refused' | 'unavailable'>;
|
|
143
145
|
/**
|
|
144
146
|
* Allow you to subscribe to an event, and
|
|
145
147
|
* verify if the event is already subscribed
|
|
@@ -711,6 +713,12 @@ declare const resetExtension: () => void;
|
|
|
711
713
|
* Mirrors `useStoreExtension.isShowSignin` from the React SDK.
|
|
712
714
|
*/
|
|
713
715
|
declare const isShowSignin: (state?: ExtensionState) => boolean;
|
|
716
|
+
/**
|
|
717
|
+
* The page is connected to the BlockAuth extension but has no session for it
|
|
718
|
+
* yet: the OTP has to be entered in the extension first (the `did` only
|
|
719
|
+
* arrives once the extension bridges its session).
|
|
720
|
+
*/
|
|
721
|
+
declare const needsExtensionUnlock: (serviceName: string | null | undefined, did: string | null | undefined, isLocked: boolean) => boolean;
|
|
714
722
|
|
|
715
723
|
interface Web3SignupState {
|
|
716
724
|
backendMessage: string | null;
|
|
@@ -1380,13 +1388,17 @@ declare const TEXTS: {
|
|
|
1380
1388
|
readonly es: "No se encontraron transacciones";
|
|
1381
1389
|
readonly en: "No transactions found";
|
|
1382
1390
|
};
|
|
1391
|
+
readonly otpExpiredTitle: {
|
|
1392
|
+
readonly es: "Verificación caducada";
|
|
1393
|
+
readonly en: "Verification expired";
|
|
1394
|
+
};
|
|
1383
1395
|
readonly otpExpiredExtension: {
|
|
1384
|
-
readonly es: "
|
|
1385
|
-
readonly en: "
|
|
1396
|
+
readonly es: "Introduce tu código en la extensión de Block-Auth para aprobar este acceso.";
|
|
1397
|
+
readonly en: "Enter your code in the Block-Auth extension to approve this access.";
|
|
1386
1398
|
};
|
|
1387
1399
|
readonly otpExpiredApp: {
|
|
1388
|
-
readonly es: "
|
|
1389
|
-
readonly en: "
|
|
1400
|
+
readonly es: "Introduce tu código en la app de Block-Auth para aprobar este acceso.";
|
|
1401
|
+
readonly en: "Enter your code in the Block-Auth app to approve this access.";
|
|
1390
1402
|
};
|
|
1391
1403
|
readonly openExtension: {
|
|
1392
1404
|
readonly es: "Abrir extensión";
|
|
@@ -2105,4 +2117,4 @@ declare function resetExtensionSyncModuleState(): void;
|
|
|
2105
2117
|
*/
|
|
2106
2118
|
declare function startExtensionSync(): () => void;
|
|
2107
2119
|
|
|
2108
|
-
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, type AuthRuntime, type AuthRuntimeCallbacks, type BlockAuthClient, type BlockAuthClientConfig, BlockAuthProvider, type BlockAuthProviderOptions, type BlockAuthUserProfile, type BlockAuthUserRole, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, type DeletionServiceDeps, EMPTY_SOLICITED_DATA_FORM, type EvmOptions, type EvmWallet, type ExtensionState, type Locale, type ModalName, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, type PhoneCountry, type PhoneCountryCode, type PhoneDraft, type PhoneParts, type RestoreResult, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, type SolanaWallet, type SolicitedAcceptParams, type SolicitedDataForm, type SolicitedField, type SolicitedParam, TEXTS, type TextKey, type TxnDataMode, type TxnDataParam, type TxnDataRequest, type TxnDataStatus, type TxnRequest, type UiState, type UserProfileProvider, type UserState, type WalletKind, type WalletState, type Web3SignupState, WsClient, type WsState, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, normalizeParamValue, index$1 as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, index as utils };
|
|
2120
|
+
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, type AuthRuntime, type AuthRuntimeCallbacks, type BlockAuthClient, type BlockAuthClientConfig, BlockAuthProvider, type BlockAuthProviderOptions, type BlockAuthUserProfile, type BlockAuthUserRole, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, type DeletionServiceDeps, EMPTY_SOLICITED_DATA_FORM, type EvmOptions, type EvmWallet, type ExtensionState, type Locale, type ModalName, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, type PhoneCountry, type PhoneCountryCode, type PhoneDraft, type PhoneParts, type RestoreResult, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, type SolanaWallet, type SolicitedAcceptParams, type SolicitedDataForm, type SolicitedField, type SolicitedParam, TEXTS, type TextKey, type TxnDataMode, type TxnDataParam, type TxnDataRequest, type TxnDataStatus, type TxnRequest, type UiState, type UserProfileProvider, type UserState, type WalletKind, type WalletState, type Web3SignupState, WsClient, type WsState, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, needsExtensionUnlock, normalizeParamValue, index$1 as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, index as utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -137,9 +137,11 @@ declare class WsClient {
|
|
|
137
137
|
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
138
138
|
* No-op if there is no open connection yet (connect() will pick up a
|
|
139
139
|
* ticket on its own once one exists).
|
|
140
|
-
* @returns
|
|
140
|
+
* @returns 'renewed' when a ticket was sent, 'refused' when the API answered
|
|
141
|
+
* 401 (no session behind the cookie), 'unavailable' otherwise (not
|
|
142
|
+
* connected yet, or a transient failure).
|
|
141
143
|
*/
|
|
142
|
-
refreshAuth(): Promise<
|
|
144
|
+
refreshAuth(): Promise<'renewed' | 'refused' | 'unavailable'>;
|
|
143
145
|
/**
|
|
144
146
|
* Allow you to subscribe to an event, and
|
|
145
147
|
* verify if the event is already subscribed
|
|
@@ -711,6 +713,12 @@ declare const resetExtension: () => void;
|
|
|
711
713
|
* Mirrors `useStoreExtension.isShowSignin` from the React SDK.
|
|
712
714
|
*/
|
|
713
715
|
declare const isShowSignin: (state?: ExtensionState) => boolean;
|
|
716
|
+
/**
|
|
717
|
+
* The page is connected to the BlockAuth extension but has no session for it
|
|
718
|
+
* yet: the OTP has to be entered in the extension first (the `did` only
|
|
719
|
+
* arrives once the extension bridges its session).
|
|
720
|
+
*/
|
|
721
|
+
declare const needsExtensionUnlock: (serviceName: string | null | undefined, did: string | null | undefined, isLocked: boolean) => boolean;
|
|
714
722
|
|
|
715
723
|
interface Web3SignupState {
|
|
716
724
|
backendMessage: string | null;
|
|
@@ -1380,13 +1388,17 @@ declare const TEXTS: {
|
|
|
1380
1388
|
readonly es: "No se encontraron transacciones";
|
|
1381
1389
|
readonly en: "No transactions found";
|
|
1382
1390
|
};
|
|
1391
|
+
readonly otpExpiredTitle: {
|
|
1392
|
+
readonly es: "Verificación caducada";
|
|
1393
|
+
readonly en: "Verification expired";
|
|
1394
|
+
};
|
|
1383
1395
|
readonly otpExpiredExtension: {
|
|
1384
|
-
readonly es: "
|
|
1385
|
-
readonly en: "
|
|
1396
|
+
readonly es: "Introduce tu código en la extensión de Block-Auth para aprobar este acceso.";
|
|
1397
|
+
readonly en: "Enter your code in the Block-Auth extension to approve this access.";
|
|
1386
1398
|
};
|
|
1387
1399
|
readonly otpExpiredApp: {
|
|
1388
|
-
readonly es: "
|
|
1389
|
-
readonly en: "
|
|
1400
|
+
readonly es: "Introduce tu código en la app de Block-Auth para aprobar este acceso.";
|
|
1401
|
+
readonly en: "Enter your code in the Block-Auth app to approve this access.";
|
|
1390
1402
|
};
|
|
1391
1403
|
readonly openExtension: {
|
|
1392
1404
|
readonly es: "Abrir extensión";
|
|
@@ -2105,4 +2117,4 @@ declare function resetExtensionSyncModuleState(): void;
|
|
|
2105
2117
|
*/
|
|
2106
2118
|
declare function startExtensionSync(): () => void;
|
|
2107
2119
|
|
|
2108
|
-
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, type AuthRuntime, type AuthRuntimeCallbacks, type BlockAuthClient, type BlockAuthClientConfig, BlockAuthProvider, type BlockAuthProviderOptions, type BlockAuthUserProfile, type BlockAuthUserRole, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, type DeletionServiceDeps, EMPTY_SOLICITED_DATA_FORM, type EvmOptions, type EvmWallet, type ExtensionState, type Locale, type ModalName, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, type PhoneCountry, type PhoneCountryCode, type PhoneDraft, type PhoneParts, type RestoreResult, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, type SolanaWallet, type SolicitedAcceptParams, type SolicitedDataForm, type SolicitedField, type SolicitedParam, TEXTS, type TextKey, type TxnDataMode, type TxnDataParam, type TxnDataRequest, type TxnDataStatus, type TxnRequest, type UiState, type UserProfileProvider, type UserState, type WalletKind, type WalletState, type Web3SignupState, WsClient, type WsState, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, normalizeParamValue, index$1 as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, index as utils };
|
|
2120
|
+
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, type AuthRuntime, type AuthRuntimeCallbacks, type BlockAuthClient, type BlockAuthClientConfig, BlockAuthProvider, type BlockAuthProviderOptions, type BlockAuthUserProfile, type BlockAuthUserRole, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, type DeletionServiceDeps, EMPTY_SOLICITED_DATA_FORM, type EvmOptions, type EvmWallet, type ExtensionState, type Locale, type ModalName, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, type PhoneCountry, type PhoneCountryCode, type PhoneDraft, type PhoneParts, type RestoreResult, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, type SolanaWallet, type SolicitedAcceptParams, type SolicitedDataForm, type SolicitedField, type SolicitedParam, TEXTS, type TextKey, type TxnDataMode, type TxnDataParam, type TxnDataRequest, type TxnDataStatus, type TxnRequest, type UiState, type UserProfileProvider, type UserState, type WalletKind, type WalletState, type Web3SignupState, WsClient, type WsState, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, needsExtensionUnlock, normalizeParamValue, index$1 as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, index as utils };
|
package/dist/index.js
CHANGED
|
@@ -49,21 +49,26 @@ async function clearSessionCookie(apiUrl) {
|
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
async function
|
|
53
|
-
if (typeof fetch === "undefined") return null;
|
|
52
|
+
async function requestWsTicket(apiUrl) {
|
|
53
|
+
if (typeof fetch === "undefined") return { ticket: null, refused: false };
|
|
54
54
|
try {
|
|
55
55
|
const response = await fetch(buildApiUrl("/auth/ws-ticket", apiUrl), {
|
|
56
56
|
method: "GET",
|
|
57
57
|
credentials: "include"
|
|
58
58
|
});
|
|
59
|
-
if (!response.ok)
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
return { ticket: null, refused: response.status === 401 };
|
|
61
|
+
}
|
|
60
62
|
const data = await response.json();
|
|
61
|
-
return data?.ticket || null;
|
|
63
|
+
return { ticket: data?.ticket || null, refused: false };
|
|
62
64
|
} catch (error) {
|
|
63
65
|
console.warn("[block-auth] failed to fetch ws ticket", error);
|
|
64
|
-
return null;
|
|
66
|
+
return { ticket: null, refused: false };
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
async function fetchWsTicket(apiUrl) {
|
|
70
|
+
return (await requestWsTicket(apiUrl)).ticket;
|
|
71
|
+
}
|
|
67
72
|
var DEFAULT_WS_URL = "wss://wss.block-auth.io";
|
|
68
73
|
function buildWsServerApiUrl(path, wsUrl) {
|
|
69
74
|
const url = new URL(wsUrl || DEFAULT_WS_URL);
|
|
@@ -212,13 +217,17 @@ var WsClient = class {
|
|
|
212
217
|
* requestSignin -> user:txns:create -> sign) - this avoids that.
|
|
213
218
|
* No-op if there is no open connection yet (connect() will pick up a
|
|
214
219
|
* ticket on its own once one exists).
|
|
215
|
-
* @returns
|
|
220
|
+
* @returns 'renewed' when a ticket was sent, 'refused' when the API answered
|
|
221
|
+
* 401 (no session behind the cookie), 'unavailable' otherwise (not
|
|
222
|
+
* connected yet, or a transient failure).
|
|
216
223
|
*/
|
|
217
224
|
async refreshAuth() {
|
|
218
|
-
if (!this.isConnected()) return;
|
|
219
|
-
const ticket = await
|
|
220
|
-
if (
|
|
225
|
+
if (!this.isConnected()) return "unavailable";
|
|
226
|
+
const { ticket, refused } = await requestWsTicket(this._apiUrl);
|
|
227
|
+
if (refused) return "refused";
|
|
228
|
+
if (!ticket) return "unavailable";
|
|
221
229
|
this._ws.emit("auth:refresh", ticket);
|
|
230
|
+
return "renewed";
|
|
222
231
|
}
|
|
223
232
|
/**
|
|
224
233
|
* Allow you to subscribe to an event, and
|
|
@@ -1086,6 +1095,7 @@ var setExtensionIsUser = (v) => $extension.setKey("isUser", v);
|
|
|
1086
1095
|
var setExtensionIsUserActive = (v) => $extension.setKey("isUserActive", v);
|
|
1087
1096
|
var resetExtension = () => $extension.set({ ...initial5 });
|
|
1088
1097
|
var isShowSignin = (state = $extension.get()) => Boolean(state.installed && state.isUser && state.isUserActive && !state.isLocked);
|
|
1098
|
+
var needsExtensionUnlock = (serviceName, did, isLocked) => serviceName === "blockauth" && (isLocked || !did);
|
|
1089
1099
|
var initial6 = { backendMessage: null, signature: null, signedBy: null };
|
|
1090
1100
|
var $web3 = map({ ...initial6 });
|
|
1091
1101
|
var setBackendMessage = (v) => $web3.setKey("backendMessage", v);
|
|
@@ -2853,6 +2863,29 @@ var undoSolicitedValue = (form, item) => ({
|
|
|
2853
2863
|
shared: (item.value ?? "").trim() ? form.shared : omitKey(form.shared, item.slug)
|
|
2854
2864
|
});
|
|
2855
2865
|
|
|
2866
|
+
// src/session/sessionExpired.ts
|
|
2867
|
+
var USER_SESSION_REQUIRED = "USER_SESSION_REQUIRED";
|
|
2868
|
+
var SESSION_EXPIRED_MARK = "blockauth-session-expired";
|
|
2869
|
+
function markSessionExpired() {
|
|
2870
|
+
try {
|
|
2871
|
+
sessionStorage.setItem(SESSION_EXPIRED_MARK, "1");
|
|
2872
|
+
} catch {
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
function hasSessionExpiredMark() {
|
|
2876
|
+
try {
|
|
2877
|
+
return sessionStorage.getItem(SESSION_EXPIRED_MARK) === "1";
|
|
2878
|
+
} catch {
|
|
2879
|
+
return false;
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
function clearSessionExpiredMark() {
|
|
2883
|
+
try {
|
|
2884
|
+
sessionStorage.removeItem(SESSION_EXPIRED_MARK);
|
|
2885
|
+
} catch {
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2856
2889
|
// src/runtime/authRuntime.ts
|
|
2857
2890
|
var SIGNIN_TIMEOUT_MS = 12e4;
|
|
2858
2891
|
var USER_TXNS_POLL_MS = 1500;
|
|
@@ -3023,6 +3056,45 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3023
3056
|
});
|
|
3024
3057
|
return logoutInFlight;
|
|
3025
3058
|
};
|
|
3059
|
+
const reactToLostSession = (isLoggingIn) => {
|
|
3060
|
+
if (browserBase.getExternalService().service === "blockauth") {
|
|
3061
|
+
if (isLoggingIn) {
|
|
3062
|
+
markSessionExpired();
|
|
3063
|
+
setIsSigningLoader(false);
|
|
3064
|
+
awaitOtpInExtension();
|
|
3065
|
+
} else if (!hasSessionExpiredMark()) {
|
|
3066
|
+
markSessionExpired();
|
|
3067
|
+
void _onError();
|
|
3068
|
+
}
|
|
3069
|
+
return;
|
|
3070
|
+
}
|
|
3071
|
+
void applyLocalLogout().then(() => {
|
|
3072
|
+
if (!isLoggingIn) return;
|
|
3073
|
+
closeModal("signin");
|
|
3074
|
+
openModal("signup");
|
|
3075
|
+
}).catch((err) => {
|
|
3076
|
+
console.error("[sdk] applyLocalLogout failed (session required):", err);
|
|
3077
|
+
});
|
|
3078
|
+
};
|
|
3079
|
+
let stopped = false;
|
|
3080
|
+
let sessionBridge = Promise.resolve();
|
|
3081
|
+
let sessionCheck = null;
|
|
3082
|
+
const canLoseSession = () => !hookState.isLoggingOut && !$ui.get().isOtpRequired && ($ui.get().isServiceConnected || hookState.isSigned);
|
|
3083
|
+
const onAnyServerEvent = (_event, data) => {
|
|
3084
|
+
if (data?.code !== USER_SESSION_REQUIRED || !canLoseSession()) return;
|
|
3085
|
+
if (sessionCheck) return;
|
|
3086
|
+
sessionCheck = (async () => {
|
|
3087
|
+
await sessionBridge.catch(() => {
|
|
3088
|
+
});
|
|
3089
|
+
const result = await wsc().refreshAuth();
|
|
3090
|
+
if (result !== "refused" || stopped || !canLoseSession()) return;
|
|
3091
|
+
reactToLostSession($openModals.get().includes("signin"));
|
|
3092
|
+
})().catch((err) => {
|
|
3093
|
+
console.error("[sdk] session check failed:", err);
|
|
3094
|
+
}).finally(() => {
|
|
3095
|
+
sessionCheck = null;
|
|
3096
|
+
});
|
|
3097
|
+
};
|
|
3026
3098
|
const onStorageLogout = (event) => {
|
|
3027
3099
|
if (event.key !== "blockauth-logged-out" || event.newValue !== "true") {
|
|
3028
3100
|
return;
|
|
@@ -3033,9 +3105,18 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3033
3105
|
});
|
|
3034
3106
|
};
|
|
3035
3107
|
let sessionBridged = false;
|
|
3036
|
-
const onExtensionSessionBridged = () => {
|
|
3108
|
+
const onExtensionSessionBridged = async () => {
|
|
3037
3109
|
sessionBridged = true;
|
|
3038
|
-
|
|
3110
|
+
const result = await wsc().refreshAuth();
|
|
3111
|
+
if (result === "refused" || !hasSessionExpiredMark()) return;
|
|
3112
|
+
clearSessionExpiredMark();
|
|
3113
|
+
const awaitedSession = $ui.get().isOtpRequired && !hookState.isSigning;
|
|
3114
|
+
if (awaitedSession) setIsOtpRequired(false);
|
|
3115
|
+
if (awaitedSession && $openModals.get().includes("signin")) {
|
|
3116
|
+
client.requestSignin();
|
|
3117
|
+
return;
|
|
3118
|
+
}
|
|
3119
|
+
if ($ws.get().ready) void isUserSignedIn();
|
|
3039
3120
|
};
|
|
3040
3121
|
const deletion = createDeletionService({ provider });
|
|
3041
3122
|
const handleUserDeleted = (forAddress = null) => {
|
|
@@ -3059,7 +3140,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3059
3140
|
if (service === "blockauth" || prevDid && prevDid.toLowerCase() !== String(did).toLowerCase()) {
|
|
3060
3141
|
browserBase.clearBrowserState({ keepExtensionInstalled: keepInstalled });
|
|
3061
3142
|
}
|
|
3062
|
-
|
|
3143
|
+
sessionBridge = browserBase.setSession({
|
|
3063
3144
|
...result,
|
|
3064
3145
|
serviceName: service,
|
|
3065
3146
|
apiUrl: client.apiUrl
|
|
@@ -3294,6 +3375,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3294
3375
|
setToken(_token);
|
|
3295
3376
|
setIsSigned(success);
|
|
3296
3377
|
hookState.isSigned = success;
|
|
3378
|
+
if (success) clearSessionExpiredMark();
|
|
3297
3379
|
if (success && hookState.isUnsignTimeoutSet && message?.signedExpiredAt) {
|
|
3298
3380
|
rearmUnsignTimeout(message.signedExpiredAt, _did);
|
|
3299
3381
|
}
|
|
@@ -3452,6 +3534,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3452
3534
|
}
|
|
3453
3535
|
};
|
|
3454
3536
|
const start = async () => {
|
|
3537
|
+
stopped = false;
|
|
3455
3538
|
const s = browserBase.getSession();
|
|
3456
3539
|
const externalService = browserBase.getExternalService();
|
|
3457
3540
|
let _token = s.token;
|
|
@@ -3512,15 +3595,21 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3512
3595
|
wsc().on("sdk:session:invalidated", onSdkSessionInvalidated);
|
|
3513
3596
|
wsc().on("sdk:user:roles:changed", onSdkUserRolesChanged);
|
|
3514
3597
|
wsc().on("sdk:restore", onSdkRestore);
|
|
3598
|
+
wsc().ws?.onAny(onAnyServerEvent);
|
|
3515
3599
|
if (typeof window !== "undefined") {
|
|
3516
3600
|
window.addEventListener("storage", onStorageLogout);
|
|
3517
3601
|
}
|
|
3518
3602
|
const { domain, signinCallbackUrl, config: config3 } = await provider.app();
|
|
3519
3603
|
setUiConfig({ domain, signinCallbackUrl, config: config3 });
|
|
3520
3604
|
setReady(true);
|
|
3605
|
+
if (externalService.service === "blockauth" && hasSessionExpiredMark()) {
|
|
3606
|
+
setIsSignedFirstCheck(true);
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3521
3609
|
await isUserSignedIn();
|
|
3522
3610
|
};
|
|
3523
3611
|
const stop = () => {
|
|
3612
|
+
stopped = true;
|
|
3524
3613
|
if (unsignTimeout) {
|
|
3525
3614
|
clearTimeout(unsignTimeout);
|
|
3526
3615
|
unsignTimeout = null;
|
|
@@ -3555,6 +3644,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
3555
3644
|
w.off("sdk:session:invalidated", onSdkSessionInvalidated);
|
|
3556
3645
|
w.off("sdk:user:roles:changed", onSdkUserRolesChanged);
|
|
3557
3646
|
w.off("sdk:restore", onSdkRestore);
|
|
3647
|
+
w.ws?.offAny(onAnyServerEvent);
|
|
3558
3648
|
}
|
|
3559
3649
|
if (typeof window !== "undefined") {
|
|
3560
3650
|
window.removeEventListener("storage", onStorageLogout);
|
|
@@ -3692,13 +3782,17 @@ var TEXTS = {
|
|
|
3692
3782
|
es: "No se encontraron transacciones",
|
|
3693
3783
|
en: "No transactions found"
|
|
3694
3784
|
},
|
|
3785
|
+
otpExpiredTitle: {
|
|
3786
|
+
es: "Verificaci\xF3n caducada",
|
|
3787
|
+
en: "Verification expired"
|
|
3788
|
+
},
|
|
3695
3789
|
otpExpiredExtension: {
|
|
3696
|
-
es: "
|
|
3697
|
-
en: "
|
|
3790
|
+
es: "Introduce tu c\xF3digo en la extensi\xF3n de Block-Auth para aprobar este acceso.",
|
|
3791
|
+
en: "Enter your code in the Block-Auth extension to approve this access."
|
|
3698
3792
|
},
|
|
3699
3793
|
otpExpiredApp: {
|
|
3700
|
-
es: "
|
|
3701
|
-
en: "
|
|
3794
|
+
es: "Introduce tu c\xF3digo en la app de Block-Auth para aprobar este acceso.",
|
|
3795
|
+
en: "Enter your code in the Block-Auth app to approve this access."
|
|
3702
3796
|
},
|
|
3703
3797
|
openExtension: { es: "Abrir extensi\xF3n", en: "Open extension" },
|
|
3704
3798
|
noAppKeyFound: {
|
|
@@ -3769,6 +3863,6 @@ function t(key, locale = "en") {
|
|
|
3769
3863
|
return entry?.[locale] ?? entry?.en ?? key;
|
|
3770
3864
|
}
|
|
3771
3865
|
|
|
3772
|
-
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, BlockAuthProvider, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, EMPTY_SOLICITED_DATA_FORM, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, TEXTS, WsClient, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, normalizeParamValue, oauth_exports as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, utils_exports as utils };
|
|
3866
|
+
export { $extension, $locale, $openModals, $ui, $user, $wallet, $web3, $ws, BlockAuthProvider, DEFAULT_PHONE_COUNTRY, DISCOVERY_TIMEOUT_MS, EMPTY_SOLICITED_DATA_FORM, PARAM_DISPLAY_FORMATTERS, PARAM_DISPLAY_ORDER, PARAM_ERROR_KEYS, PARAM_INPUT_TYPE, PARAM_LABEL_KEYS, PARAM_NORMALIZERS, PARAM_VALIDATORS, RpcClient, SDK_PAGE_MARKER, SYNC_TIMEOUT_MS, TEXTS, WsClient, appearsExtensionInstalled, buildPhoneE164, buildPhoneValue, clearExtensionDomMarkers, clearRemainingAuthData, clearSdkPresence, closeAllModals, closeModal, confirmExtensionPresence, createAuthRuntime, createBlockAuthClient, createDeletionService, createEvmWallet, createSolanaWallet, deepLinkFor, discoverExtensionOnce, fetchUserProfile, finalizeAfterRestorationExpired, formatParamValue, formatPhoneForDisplay, getDefaultPhoneCountry, getExtensionStoreUrl, getPhoneCountries, getPhoneCountryFlag, getPhoneDialCode, getSolicitedAcceptParams, getSolicitedFields, getSolicitedHintKey, getSolicitedParams, getUserRoleNames, getUserRoleSlugs, getUserRoles, handleRestorationExpired, handleRestoreFailure, hasAnyRole, hasAnyRoleBySlug, hasRole, hasRoleBySlug, isExtensionPresent, isExtensionStateComplete, isFirefox, isModalOpen, isPhoneCountry, isRestorationExpiredMessage, isSdkPage, isShowSignin, isSolicitedDataComplete, isSolicitedHintSuccess, isValidParamValue, isValidPhoneValue, loadUserProfile, makeQrDataUrl, markSdkPresence, needsExtensionUnlock, normalizeParamValue, oauth_exports as oauth, onExtensionRemoved, onExtensionStatePublished, openExtensionOnTxn, openModal, parsePhoneValue, probeExtensionPresence, reconcileExtensionState, requestExtensionRefresh, requestExtensionStateSync, requestSdkRestore, resetExtension, resetExtensionAbsentState, resetExtensionSyncModuleState, resetUi, resetUser, resetWallet, resetWeb3, resetWs, resolvePhoneDraft, saveSolicitedValue, searchPhoneCountries, setAcceptTxnError, setApiKey, setBackendMessage, setDeletionAddress, setDid, setExtensionInstalled, setExtensionIsLocked, setExtensionIsUser, setExtensionIsUserActive, setIsAcceptingTxn, setIsAppActive, setIsCheckingAppActive, setIsLoadingUser, setIsOnDeletion, setIsOtpRequired, setIsSdkSignedIn, setIsServiceConnected, setIsSigned, setIsSignedFirstCheck, setIsSigning, setIsSigningLoader, setLocale, setReady, setRequests, setServiceIcon, setServiceName, setSignature, setSignedBy, setSolicitedShared, setSolicitedValue, setToken, setUiConfig, setUser, setWaitingForSuccessLogInSince, startExtensionSync, syncExtensionStateFromStorage, t, toPhoneE164, undoSolicitedValue, updatePhoneDraft, utils_exports as utils };
|
|
3773
3867
|
//# sourceMappingURL=index.js.map
|
|
3774
3868
|
//# sourceMappingURL=index.js.map
|