@block-auth.io/core 0.9.0 → 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 +24 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2430,6 +2430,9 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2430
2430
|
const provider = client.provider;
|
|
2431
2431
|
const hookState = {
|
|
2432
2432
|
isUnsignTimeoutSet: false,
|
|
2433
|
+
// When the current L1 signature expires (epoch ms), set with the unsign
|
|
2434
|
+
// timeout; 0 when unknown. Read only while isUnsignTimeoutSet holds.
|
|
2435
|
+
signedExpiresAtMs: 0,
|
|
2433
2436
|
isSigned: false,
|
|
2434
2437
|
isSigning: false,
|
|
2435
2438
|
isLoggingOut: false,
|
|
@@ -2683,17 +2686,35 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2683
2686
|
const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
|
|
2684
2687
|
const signedExpiredAt = new Date(signedExpiredAtDateString);
|
|
2685
2688
|
const timeDifference = signedExpiredAt.getTime() - currentDate.getTime();
|
|
2689
|
+
hookState.signedExpiresAtMs = Number.isFinite(timeDifference) ? Date.now() + timeDifference : 0;
|
|
2686
2690
|
unsignTimeout = setTimeout(() => {
|
|
2687
2691
|
emitSdkSign(wsc().accessToken, did);
|
|
2688
2692
|
}, timeDifference);
|
|
2689
2693
|
};
|
|
2694
|
+
const rearmUnsignTimeout = (signedExpiredAtDateString, did = "") => {
|
|
2695
|
+
const currentDate = new Date(getUTCDateString(/* @__PURE__ */ new Date()));
|
|
2696
|
+
const timeDifference = new Date(signedExpiredAtDateString).getTime() - currentDate.getTime();
|
|
2697
|
+
if (!Number.isFinite(timeDifference)) return;
|
|
2698
|
+
const expiresAtMs = Date.now() + timeDifference;
|
|
2699
|
+
if (Math.abs(expiresAtMs - hookState.signedExpiresAtMs) <= 1e3) return;
|
|
2700
|
+
if (unsignTimeout) {
|
|
2701
|
+
clearTimeout(unsignTimeout);
|
|
2702
|
+
unsignTimeout = null;
|
|
2703
|
+
}
|
|
2704
|
+
setUnsignTimeout(signedExpiredAtDateString, did);
|
|
2705
|
+
};
|
|
2690
2706
|
const signinUnsigned = async () => {
|
|
2691
2707
|
setIsSignedFirstCheck(true);
|
|
2692
2708
|
if (hookState.isSigning) return;
|
|
2693
2709
|
if (!hookState.isSigned) {
|
|
2694
2710
|
await _onError();
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
if (signatureExpired()) {
|
|
2714
|
+
await _onError();
|
|
2695
2715
|
}
|
|
2696
2716
|
};
|
|
2717
|
+
const signatureExpired = () => hookState.isUnsignTimeoutSet && hookState.signedExpiresAtMs > 0 && Date.now() >= hookState.signedExpiresAtMs;
|
|
2697
2718
|
const onProviderSignup = (data) => {
|
|
2698
2719
|
const { success, message } = data;
|
|
2699
2720
|
if (!success) {
|
|
@@ -2838,6 +2859,9 @@ function createAuthRuntime(client, callbacks = {}) {
|
|
|
2838
2859
|
setToken(_token);
|
|
2839
2860
|
setIsSigned(success);
|
|
2840
2861
|
hookState.isSigned = success;
|
|
2862
|
+
if (success && hookState.isUnsignTimeoutSet && message?.signedExpiredAt) {
|
|
2863
|
+
rearmUnsignTimeout(message.signedExpiredAt, _did);
|
|
2864
|
+
}
|
|
2841
2865
|
if (success && !hookState.isUnsignTimeoutSet) {
|
|
2842
2866
|
if (typeof localStorage !== "undefined") {
|
|
2843
2867
|
localStorage.removeItem("blockauth-logged-out");
|