@block-auth.io/core 0.8.1 → 0.9.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 +54 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +53 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -994,6 +994,7 @@ var initial2 = {
|
|
|
994
994
|
isSigningLoader: false,
|
|
995
995
|
isAcceptingTxn: false,
|
|
996
996
|
waitingForSuccessLogInSince: 0,
|
|
997
|
+
isOtpRequired: false,
|
|
997
998
|
isOnDeletion: false,
|
|
998
999
|
deletionAddress: null
|
|
999
1000
|
};
|
|
@@ -1011,6 +1012,7 @@ var setIsSigned = (v) => $ui.setKey("isSigned", v);
|
|
|
1011
1012
|
var setIsSigningLoader = (v) => $ui.setKey("isSigningLoader", v);
|
|
1012
1013
|
var setIsAcceptingTxn = (v) => $ui.setKey("isAcceptingTxn", v);
|
|
1013
1014
|
var setWaitingForSuccessLogInSince = (v) => $ui.setKey("waitingForSuccessLogInSince", v);
|
|
1015
|
+
var setIsOtpRequired = (v) => $ui.setKey("isOtpRequired", v);
|
|
1014
1016
|
var setIsOnDeletion = (v) => $ui.setKey("isOnDeletion", v);
|
|
1015
1017
|
var setDeletionAddress = (v) => $ui.setKey("deletionAddress", v);
|
|
1016
1018
|
var resetUi = () => $ui.set({ ...initial2 });
|
|
@@ -1790,6 +1792,10 @@ function requestExtensionStateSync() {
|
|
|
1790
1792
|
if (typeof document === "undefined") return;
|
|
1791
1793
|
document.dispatchEvent(new CustomEvent("ext:initial"));
|
|
1792
1794
|
}
|
|
1795
|
+
function openExtensionOnTxn() {
|
|
1796
|
+
if (typeof document === "undefined") return;
|
|
1797
|
+
document.dispatchEvent(new CustomEvent("ext:txn"));
|
|
1798
|
+
}
|
|
1793
1799
|
function syncExtensionStateFromStorage() {
|
|
1794
1800
|
const ui = browserBase.getUI();
|
|
1795
1801
|
const state = $extension.get();
|
|
@@ -2432,6 +2438,9 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2432
2438
|
const provider = client.provider;
|
|
2433
2439
|
const hookState = {
|
|
2434
2440
|
isUnsignTimeoutSet: false,
|
|
2441
|
+
// When the current L1 signature expires (epoch ms), set with the unsign
|
|
2442
|
+
// timeout; 0 when unknown. Read only while isUnsignTimeoutSet holds.
|
|
2443
|
+
signedExpiresAtMs: 0,
|
|
2435
2444
|
isSigned: false,
|
|
2436
2445
|
isSigning: false,
|
|
2437
2446
|
isLoggingOut: false,
|
|
@@ -2504,10 +2513,16 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2504
2513
|
setIsSigning(false);
|
|
2505
2514
|
setIsSigningLoader(false);
|
|
2506
2515
|
setIsAcceptingTxn(false);
|
|
2516
|
+
setIsOtpRequired(false);
|
|
2507
2517
|
closeAllModals();
|
|
2508
2518
|
resetUser();
|
|
2509
2519
|
await onError();
|
|
2510
2520
|
};
|
|
2521
|
+
const awaitOtpInExtension = () => {
|
|
2522
|
+
setIsOtpRequired(true);
|
|
2523
|
+
setIsAcceptingTxn(false);
|
|
2524
|
+
if ($extension.get().installed) openExtensionOnTxn();
|
|
2525
|
+
};
|
|
2511
2526
|
const _onLogout = async () => {
|
|
2512
2527
|
if (hookState.isLoggingOut) return applyLocalLogout();
|
|
2513
2528
|
hookState.isLoggingOut = true;
|
|
@@ -2679,17 +2694,35 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2679
2694
|
const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
|
|
2680
2695
|
const signedExpiredAt = new Date(signedExpiredAtDateString);
|
|
2681
2696
|
const timeDifference = signedExpiredAt.getTime() - currentDate.getTime();
|
|
2697
|
+
hookState.signedExpiresAtMs = Number.isFinite(timeDifference) ? Date.now() + timeDifference : 0;
|
|
2682
2698
|
unsignTimeout = setTimeout(() => {
|
|
2683
2699
|
emitSdkSign(wsc().accessToken, did);
|
|
2684
2700
|
}, timeDifference);
|
|
2685
2701
|
};
|
|
2702
|
+
const rearmUnsignTimeout = (signedExpiredAtDateString, did = "") => {
|
|
2703
|
+
const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
|
|
2704
|
+
const timeDifference = new Date(signedExpiredAtDateString).getTime() - currentDate.getTime();
|
|
2705
|
+
if (!Number.isFinite(timeDifference)) return;
|
|
2706
|
+
const expiresAtMs = Date.now() + timeDifference;
|
|
2707
|
+
if (Math.abs(expiresAtMs - hookState.signedExpiresAtMs) <= 1e3) return;
|
|
2708
|
+
if (unsignTimeout) {
|
|
2709
|
+
clearTimeout(unsignTimeout);
|
|
2710
|
+
unsignTimeout = null;
|
|
2711
|
+
}
|
|
2712
|
+
setUnsignTimeout(signedExpiredAtDateString, did);
|
|
2713
|
+
};
|
|
2686
2714
|
const signinUnsigned = async () => {
|
|
2687
2715
|
setIsSignedFirstCheck(true);
|
|
2688
2716
|
if (hookState.isSigning) return;
|
|
2689
2717
|
if (!hookState.isSigned) {
|
|
2690
2718
|
await _onError();
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
if (signatureExpired()) {
|
|
2722
|
+
await _onError();
|
|
2691
2723
|
}
|
|
2692
2724
|
};
|
|
2725
|
+
const signatureExpired = () => hookState.isUnsignTimeoutSet && hookState.signedExpiresAtMs > 0 && Date.now() >= hookState.signedExpiresAtMs;
|
|
2693
2726
|
const onProviderSignup = (data) => {
|
|
2694
2727
|
const { success, message } = data;
|
|
2695
2728
|
if (!success) {
|
|
@@ -2730,6 +2763,7 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2730
2763
|
};
|
|
2731
2764
|
const settleSigningAttempt = (outcome) => {
|
|
2732
2765
|
setWaitingForSuccessLogInSince(0);
|
|
2766
|
+
setIsOtpRequired(false);
|
|
2733
2767
|
setIsSigning(false);
|
|
2734
2768
|
hookState.isSigning = false;
|
|
2735
2769
|
if (getUserTxnsInterval) {
|
|
@@ -2809,6 +2843,8 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2809
2843
|
captureOwnTxnId(ownTxnItems(message?.items ?? []));
|
|
2810
2844
|
wsc().emit("user:txns", { token });
|
|
2811
2845
|
pollUserTxns(token, () => hookState.isSigning, USER_TXNS_POLL_MS);
|
|
2846
|
+
if (message?.otpExpired) awaitOtpInExtension();
|
|
2847
|
+
else setIsOtpRequired(false);
|
|
2812
2848
|
} else {
|
|
2813
2849
|
setIsSigning(false);
|
|
2814
2850
|
hookState.isSigning = false;
|
|
@@ -2831,6 +2867,9 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2831
2867
|
setToken(_token);
|
|
2832
2868
|
setIsSigned(success);
|
|
2833
2869
|
hookState.isSigned = success;
|
|
2870
|
+
if (success && hookState.isUnsignTimeoutSet && message?.signedExpiredAt) {
|
|
2871
|
+
rearmUnsignTimeout(message.signedExpiredAt, _did);
|
|
2872
|
+
}
|
|
2834
2873
|
if (success && !hookState.isUnsignTimeoutSet) {
|
|
2835
2874
|
if (typeof localStorage !== "undefined") {
|
|
2836
2875
|
localStorage.removeItem("blockauth-logged-out");
|
|
@@ -2863,6 +2902,10 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2863
2902
|
handleUserDeleted(corruptedAddress);
|
|
2864
2903
|
};
|
|
2865
2904
|
const onSigninExpired = async (_data) => {
|
|
2905
|
+
if (hookState.isSigning) {
|
|
2906
|
+
awaitOtpInExtension();
|
|
2907
|
+
return;
|
|
2908
|
+
}
|
|
2866
2909
|
await _onError();
|
|
2867
2910
|
};
|
|
2868
2911
|
const onSigninUnsigned = async (_data) => {
|
|
@@ -3197,6 +3240,15 @@ var TEXTS = {
|
|
|
3197
3240
|
es: "No se encontraron transacciones",
|
|
3198
3241
|
en: "No transactions found"
|
|
3199
3242
|
},
|
|
3243
|
+
otpExpiredExtension: {
|
|
3244
|
+
es: "Tu verificaci\xF3n ha caducado. Introduce tu c\xF3digo en la extensi\xF3n de Block-Auth para aprobar este acceso.",
|
|
3245
|
+
en: "Your verification has expired. Enter your code in the Block-Auth extension to approve this access."
|
|
3246
|
+
},
|
|
3247
|
+
otpExpiredApp: {
|
|
3248
|
+
es: "Tu verificaci\xF3n ha caducado. Introduce tu c\xF3digo en la app de Block-Auth para aprobar este acceso.",
|
|
3249
|
+
en: "Your verification has expired. Enter your code in the Block-Auth app to approve this access."
|
|
3250
|
+
},
|
|
3251
|
+
openExtension: { es: "Abrir extensi\xF3n", en: "Open extension" },
|
|
3200
3252
|
noAppKeyFound: {
|
|
3201
3253
|
es: "No se encontr\xF3 la clave de la aplicaci\xF3n",
|
|
3202
3254
|
en: "No application key found"
|
|
@@ -3313,6 +3365,7 @@ exports.markSdkPresence = markSdkPresence;
|
|
|
3313
3365
|
exports.oauth = oauth_exports;
|
|
3314
3366
|
exports.onExtensionRemoved = onExtensionRemoved;
|
|
3315
3367
|
exports.onExtensionStatePublished = onExtensionStatePublished;
|
|
3368
|
+
exports.openExtensionOnTxn = openExtensionOnTxn;
|
|
3316
3369
|
exports.openModal = openModal;
|
|
3317
3370
|
exports.probeExtensionPresence = probeExtensionPresence;
|
|
3318
3371
|
exports.reconcileExtensionState = reconcileExtensionState;
|
|
@@ -3340,6 +3393,7 @@ exports.setIsAppActive = setIsAppActive;
|
|
|
3340
3393
|
exports.setIsCheckingAppActive = setIsCheckingAppActive;
|
|
3341
3394
|
exports.setIsLoadingUser = setIsLoadingUser;
|
|
3342
3395
|
exports.setIsOnDeletion = setIsOnDeletion;
|
|
3396
|
+
exports.setIsOtpRequired = setIsOtpRequired;
|
|
3343
3397
|
exports.setIsSdkSignedIn = setIsSdkSignedIn;
|
|
3344
3398
|
exports.setIsServiceConnected = setIsServiceConnected;
|
|
3345
3399
|
exports.setIsSigned = setIsSigned;
|