eocene-auth-sdk 0.4.0 → 0.5.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/index.d.ts +119 -10
- package/dist/index.js +582 -44
- package/dist/index.js.map +1 -1
- package/dist/styles.css +73 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2600,6 +2600,16 @@ function normalizeErrorCode(body, status) {
|
|
|
2600
2600
|
if (raw === "PLAN_USER_LIMIT" || raw === "plan_user_limit") return "plan_user_limit";
|
|
2601
2601
|
if (raw === "PLAN_PROJECT_LIMIT" || raw === "plan_project_limit") return "plan_project_limit";
|
|
2602
2602
|
if (raw === "RATE_LIMITED" || raw === "rate_limited") return "rate_limited";
|
|
2603
|
+
if (raw === "reset_cooldown") return "reset_cooldown";
|
|
2604
|
+
if (raw === "reset_code_invalid") return "reset_code_invalid";
|
|
2605
|
+
if (raw === "reset_code_expired") return "reset_code_expired";
|
|
2606
|
+
if (raw === "reset_code_locked") return "reset_code_locked";
|
|
2607
|
+
if (raw === "reset_channel_unavailable") return "reset_channel_unavailable";
|
|
2608
|
+
if (raw === "reset_delivery_failed") return "reset_delivery_failed";
|
|
2609
|
+
if (raw === "password_not_enabled") return "password_not_enabled";
|
|
2610
|
+
if (raw === "recovery_contact_required") return "recovery_contact_required";
|
|
2611
|
+
if (raw === "invalid_recovery_email") return "invalid_recovery_email";
|
|
2612
|
+
if (raw === "password_too_short") return "password_too_short";
|
|
2603
2613
|
if (raw === "password_locked" || raw.includes("password_locked")) return "password_locked";
|
|
2604
2614
|
if (raw === "password_invalid") return "password_invalid";
|
|
2605
2615
|
if (raw.includes("at least 6")) return "password_too_short";
|
|
@@ -2887,7 +2897,8 @@ var WaasClient = class {
|
|
|
2887
2897
|
walletId: me.wallet?.walletId,
|
|
2888
2898
|
address: me.wallet?.address,
|
|
2889
2899
|
epoch: me.wallet?.epoch,
|
|
2890
|
-
passwordEnabled: me.wallet?.passwordEnabled ?? false
|
|
2900
|
+
passwordEnabled: me.wallet?.passwordEnabled ?? false,
|
|
2901
|
+
recovery: me.wallet?.recovery
|
|
2891
2902
|
};
|
|
2892
2903
|
return this.getState();
|
|
2893
2904
|
}
|
|
@@ -2897,29 +2908,71 @@ var WaasClient = class {
|
|
|
2897
2908
|
headers: this.authHeaders()
|
|
2898
2909
|
});
|
|
2899
2910
|
}
|
|
2900
|
-
async ensureWallet() {
|
|
2911
|
+
async ensureWallet(opts) {
|
|
2901
2912
|
this.requireSession();
|
|
2913
|
+
const hasInitData = Boolean(opts?.telegramInitData);
|
|
2902
2914
|
const out = await this.authed(`${this.controlBaseUrl}/wallet/ensure`, {
|
|
2903
2915
|
method: "POST",
|
|
2904
|
-
headers: this.authHeaders()
|
|
2916
|
+
headers: hasInitData ? { ...this.authHeaders(), "content-type": "application/json" } : this.authHeaders(),
|
|
2917
|
+
body: hasInitData ? JSON.stringify({ telegramInitData: opts.telegramInitData }) : void 0
|
|
2905
2918
|
});
|
|
2906
2919
|
this.state = {
|
|
2907
2920
|
...this.state,
|
|
2908
2921
|
walletId: out.walletId,
|
|
2909
2922
|
address: out.address,
|
|
2910
2923
|
epoch: out.epoch,
|
|
2911
|
-
passwordEnabled: out.passwordEnabled
|
|
2924
|
+
passwordEnabled: out.passwordEnabled,
|
|
2925
|
+
recovery: out.recovery ?? this.state?.recovery
|
|
2926
|
+
};
|
|
2927
|
+
return {
|
|
2928
|
+
walletId: out.walletId,
|
|
2929
|
+
address: out.address,
|
|
2930
|
+
passwordEnabled: out.passwordEnabled,
|
|
2931
|
+
recovery: out.recovery
|
|
2912
2932
|
};
|
|
2913
|
-
return { walletId: out.walletId, address: out.address, passwordEnabled: out.passwordEnabled };
|
|
2914
2933
|
}
|
|
2915
|
-
async setPassword(password, currentPassword) {
|
|
2934
|
+
async setPassword(password, currentPassword, recoveryBind) {
|
|
2916
2935
|
this.requireSession();
|
|
2917
|
-
await this.authed(`${this.controlBaseUrl}/wallet/password/set`, {
|
|
2936
|
+
const out = await this.authed(`${this.controlBaseUrl}/wallet/password/set`, {
|
|
2918
2937
|
method: "POST",
|
|
2919
2938
|
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2920
|
-
body: JSON.stringify({
|
|
2939
|
+
body: JSON.stringify({
|
|
2940
|
+
password,
|
|
2941
|
+
currentPassword,
|
|
2942
|
+
recoveryEmail: recoveryBind?.recoveryEmail,
|
|
2943
|
+
recoveryCode: recoveryBind?.recoveryCode
|
|
2944
|
+
})
|
|
2921
2945
|
});
|
|
2922
|
-
if (this.state)
|
|
2946
|
+
if (this.state) {
|
|
2947
|
+
this.state.passwordEnabled = true;
|
|
2948
|
+
if (out.recovery) this.state.recovery = out.recovery;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
async requestRecoveryEmailBind(email) {
|
|
2952
|
+
this.requireSession();
|
|
2953
|
+
return this.authed(
|
|
2954
|
+
`${this.controlBaseUrl}/wallet/recovery/email/request`,
|
|
2955
|
+
{
|
|
2956
|
+
method: "POST",
|
|
2957
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2958
|
+
body: JSON.stringify({ email })
|
|
2959
|
+
}
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
async confirmRecoveryEmailBind(code, email) {
|
|
2963
|
+
this.requireSession();
|
|
2964
|
+
const out = await this.authed(
|
|
2965
|
+
`${this.controlBaseUrl}/wallet/recovery/email/confirm`,
|
|
2966
|
+
{
|
|
2967
|
+
method: "POST",
|
|
2968
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2969
|
+
body: JSON.stringify({ code, email })
|
|
2970
|
+
}
|
|
2971
|
+
);
|
|
2972
|
+
if (this.state && out.recovery) {
|
|
2973
|
+
this.state.recovery = out.recovery;
|
|
2974
|
+
}
|
|
2975
|
+
return out;
|
|
2923
2976
|
}
|
|
2924
2977
|
async clearPassword(password) {
|
|
2925
2978
|
this.requireSession();
|
|
@@ -2930,6 +2983,30 @@ var WaasClient = class {
|
|
|
2930
2983
|
});
|
|
2931
2984
|
if (this.state) this.state.passwordEnabled = false;
|
|
2932
2985
|
}
|
|
2986
|
+
async requestPasswordReset(channel) {
|
|
2987
|
+
this.requireSession();
|
|
2988
|
+
return this.authed(
|
|
2989
|
+
`${this.controlBaseUrl}/wallet/password/reset/request`,
|
|
2990
|
+
{
|
|
2991
|
+
method: "POST",
|
|
2992
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
2993
|
+
body: JSON.stringify(channel ? { channel } : {})
|
|
2994
|
+
}
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
async confirmPasswordReset(code, newPassword) {
|
|
2998
|
+
this.requireSession();
|
|
2999
|
+
const out = await this.authed(
|
|
3000
|
+
`${this.controlBaseUrl}/wallet/password/reset/confirm`,
|
|
3001
|
+
{
|
|
3002
|
+
method: "POST",
|
|
3003
|
+
headers: { ...this.authHeaders(), "content-type": "application/json" },
|
|
3004
|
+
body: JSON.stringify({ code, newPassword })
|
|
3005
|
+
}
|
|
3006
|
+
);
|
|
3007
|
+
if (this.state) this.state.passwordEnabled = out.passwordEnabled;
|
|
3008
|
+
return out;
|
|
3009
|
+
}
|
|
2933
3010
|
async signMessage(message, opts) {
|
|
2934
3011
|
const digest = hashPersonalMessage(message);
|
|
2935
3012
|
return this.signDigestHex(digestToHex(digest), opts);
|
|
@@ -3113,7 +3190,8 @@ var AuthClient = class {
|
|
|
3113
3190
|
email: s.email,
|
|
3114
3191
|
address: s.address,
|
|
3115
3192
|
walletId: s.walletId,
|
|
3116
|
-
passwordEnabled: s.passwordEnabled
|
|
3193
|
+
passwordEnabled: s.passwordEnabled,
|
|
3194
|
+
recovery: s.recovery
|
|
3117
3195
|
};
|
|
3118
3196
|
}
|
|
3119
3197
|
/** Current EIP-1193 chain. Changes via wallet_switchEthereumChain. */
|
|
@@ -3226,7 +3304,9 @@ var AuthClient = class {
|
|
|
3226
3304
|
}
|
|
3227
3305
|
}
|
|
3228
3306
|
}
|
|
3229
|
-
const wallet = await this.client.ensureWallet(
|
|
3307
|
+
const wallet = await this.client.ensureWallet({
|
|
3308
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3309
|
+
});
|
|
3230
3310
|
this.persist();
|
|
3231
3311
|
this.active = true;
|
|
3232
3312
|
this.provider = null;
|
|
@@ -3257,7 +3337,7 @@ var AuthClient = class {
|
|
|
3257
3337
|
throw new Error(body.error ?? `telegram miniapp login HTTP ${res.status}`);
|
|
3258
3338
|
}
|
|
3259
3339
|
await this.client.loginWithSessionToken(body.sessionToken);
|
|
3260
|
-
const wallet = await this.client.ensureWallet();
|
|
3340
|
+
const wallet = await this.client.ensureWallet({ telegramInitData: data });
|
|
3261
3341
|
this.persist();
|
|
3262
3342
|
this.active = true;
|
|
3263
3343
|
this.provider = null;
|
|
@@ -3272,7 +3352,9 @@ var AuthClient = class {
|
|
|
3272
3352
|
if (!sessionToken) throw new Error("missing waas_session in callback");
|
|
3273
3353
|
const provider = params.get("waas_provider") ?? void 0;
|
|
3274
3354
|
await this.client.loginWithSessionToken(decodeURIComponent(sessionToken));
|
|
3275
|
-
const wallet = await this.client.ensureWallet(
|
|
3355
|
+
const wallet = await this.client.ensureWallet({
|
|
3356
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3357
|
+
});
|
|
3276
3358
|
this.persist();
|
|
3277
3359
|
this.active = true;
|
|
3278
3360
|
this.provider = null;
|
|
@@ -3356,7 +3438,9 @@ var AuthClient = class {
|
|
|
3356
3438
|
const result = await res.json().catch(() => ({}));
|
|
3357
3439
|
if (!res.ok || !result.sessionToken) throw new Error(`session refresh HTTP ${res.status}`);
|
|
3358
3440
|
await this.client.loginWithSessionToken(result.sessionToken);
|
|
3359
|
-
await this.client.ensureWallet(
|
|
3441
|
+
await this.client.ensureWallet({
|
|
3442
|
+
telegramInitData: getTelegramInitData() ?? void 0
|
|
3443
|
+
});
|
|
3360
3444
|
this.persist();
|
|
3361
3445
|
this.active = true;
|
|
3362
3446
|
this.provider = null;
|
|
@@ -3386,14 +3470,30 @@ var AuthClient = class {
|
|
|
3386
3470
|
this.markActive(false);
|
|
3387
3471
|
}
|
|
3388
3472
|
}
|
|
3389
|
-
async setPassword(password, currentPassword) {
|
|
3390
|
-
await this.client.setPassword(password, currentPassword);
|
|
3473
|
+
async setPassword(password, currentPassword, recoveryBind) {
|
|
3474
|
+
await this.client.setPassword(password, currentPassword, recoveryBind);
|
|
3391
3475
|
this.persist();
|
|
3392
3476
|
}
|
|
3393
3477
|
async clearPassword(password) {
|
|
3394
3478
|
await this.client.clearPassword(password);
|
|
3395
3479
|
this.persist();
|
|
3396
3480
|
}
|
|
3481
|
+
async requestRecoveryEmailBind(email) {
|
|
3482
|
+
return this.client.requestRecoveryEmailBind(email);
|
|
3483
|
+
}
|
|
3484
|
+
async confirmRecoveryEmailBind(code, email) {
|
|
3485
|
+
const out = await this.client.confirmRecoveryEmailBind(code, email);
|
|
3486
|
+
this.persist();
|
|
3487
|
+
return out;
|
|
3488
|
+
}
|
|
3489
|
+
async requestPasswordReset(channel) {
|
|
3490
|
+
return this.client.requestPasswordReset(channel);
|
|
3491
|
+
}
|
|
3492
|
+
async confirmPasswordReset(code, newPassword) {
|
|
3493
|
+
const out = await this.client.confirmPasswordReset(code, newPassword);
|
|
3494
|
+
this.persist();
|
|
3495
|
+
return out;
|
|
3496
|
+
}
|
|
3397
3497
|
};
|
|
3398
3498
|
|
|
3399
3499
|
// src/provider/createProvider.ts
|
|
@@ -3412,6 +3512,27 @@ function formatAuthError(e, labels) {
|
|
|
3412
3512
|
if (e.code === "plan_project_limit") {
|
|
3413
3513
|
return "Project limit reached on this Eocene account.";
|
|
3414
3514
|
}
|
|
3515
|
+
if (e.code === "reset_code_invalid") return labels.passwordSettingsResetCodeInvalid;
|
|
3516
|
+
if (e.code === "reset_code_expired") return labels.passwordSettingsResetCodeExpired;
|
|
3517
|
+
if (e.code === "reset_code_locked") return labels.passwordSettingsResetCodeLocked;
|
|
3518
|
+
if (e.code === "reset_cooldown") {
|
|
3519
|
+
return labels.passwordSettingsResetCooldown.replace(
|
|
3520
|
+
"{seconds}",
|
|
3521
|
+
String(e.retryAfterSec ?? 60)
|
|
3522
|
+
);
|
|
3523
|
+
}
|
|
3524
|
+
if (e.code === "reset_channel_unavailable") {
|
|
3525
|
+
return labels.passwordSettingsResetChannelUnavailable;
|
|
3526
|
+
}
|
|
3527
|
+
if (e.code === "reset_delivery_failed") {
|
|
3528
|
+
return e.message || labels.passwordSettingsResetDeliveryFailed;
|
|
3529
|
+
}
|
|
3530
|
+
if (e.code === "recovery_contact_required") {
|
|
3531
|
+
return labels.passwordSettingsRecoveryRequired;
|
|
3532
|
+
}
|
|
3533
|
+
if (e.code === "invalid_recovery_email") {
|
|
3534
|
+
return labels.passwordSettingsInvalidRecoveryEmail;
|
|
3535
|
+
}
|
|
3415
3536
|
return formatSignAuthError(
|
|
3416
3537
|
{
|
|
3417
3538
|
code: e.code,
|
|
@@ -3673,28 +3794,96 @@ function AuthLoginPanel({
|
|
|
3673
3794
|
function SetPasswordModal({
|
|
3674
3795
|
open,
|
|
3675
3796
|
passwordEnabled,
|
|
3797
|
+
initialMode,
|
|
3798
|
+
recovery,
|
|
3676
3799
|
labels,
|
|
3677
3800
|
busy,
|
|
3801
|
+
sendingResetCode = false,
|
|
3802
|
+
resetSent = null,
|
|
3803
|
+
sendingRecoveryBindCode = false,
|
|
3804
|
+
recoveryBindSent = null,
|
|
3678
3805
|
error,
|
|
3679
3806
|
onSubmitSet,
|
|
3680
3807
|
onSubmitClear,
|
|
3808
|
+
onRequestResetCode,
|
|
3809
|
+
onSubmitReset,
|
|
3810
|
+
onRequestRecoveryEmailBind,
|
|
3681
3811
|
onClose
|
|
3682
3812
|
}) {
|
|
3683
3813
|
const [password, setPassword] = useState("");
|
|
3684
3814
|
const [confirm, setConfirm] = useState("");
|
|
3685
3815
|
const [current, setCurrent] = useState("");
|
|
3816
|
+
const [code, setCode] = useState("");
|
|
3817
|
+
const [recoveryEmail, setRecoveryEmail] = useState("");
|
|
3818
|
+
const [recoveryCode, setRecoveryCode] = useState("");
|
|
3819
|
+
const [selectedChannel, setSelectedChannel] = useState(
|
|
3820
|
+
void 0
|
|
3821
|
+
);
|
|
3686
3822
|
const [mode, setMode] = useState("set");
|
|
3823
|
+
const [cooldownLeft, setCooldownLeft] = useState(0);
|
|
3824
|
+
const [bindCooldownLeft, setBindCooldownLeft] = useState(0);
|
|
3687
3825
|
useEffect(() => {
|
|
3688
3826
|
if (!open) return;
|
|
3689
3827
|
setPassword("");
|
|
3690
3828
|
setConfirm("");
|
|
3691
3829
|
setCurrent("");
|
|
3692
|
-
|
|
3693
|
-
|
|
3830
|
+
setCode("");
|
|
3831
|
+
setRecoveryEmail("");
|
|
3832
|
+
setRecoveryCode("");
|
|
3833
|
+
setSelectedChannel(recovery?.defaultChannel ?? void 0);
|
|
3834
|
+
setMode(passwordEnabled && initialMode ? initialMode : "set");
|
|
3835
|
+
}, [open, passwordEnabled, initialMode, recovery?.defaultChannel]);
|
|
3836
|
+
useEffect(() => {
|
|
3837
|
+
if (!open || !resetSent) {
|
|
3838
|
+
setCooldownLeft(0);
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
const update = () => {
|
|
3842
|
+
const rem = Math.max(
|
|
3843
|
+
0,
|
|
3844
|
+
Math.ceil((resetSent.sentAt + resetSent.cooldownSec * 1e3 - Date.now()) / 1e3)
|
|
3845
|
+
);
|
|
3846
|
+
setCooldownLeft(rem);
|
|
3847
|
+
};
|
|
3848
|
+
update();
|
|
3849
|
+
const timer = window.setInterval(update, 1e3);
|
|
3850
|
+
return () => window.clearInterval(timer);
|
|
3851
|
+
}, [open, resetSent]);
|
|
3852
|
+
useEffect(() => {
|
|
3853
|
+
if (!open || !recoveryBindSent) {
|
|
3854
|
+
setBindCooldownLeft(0);
|
|
3855
|
+
return;
|
|
3856
|
+
}
|
|
3857
|
+
const update = () => {
|
|
3858
|
+
const rem = Math.max(
|
|
3859
|
+
0,
|
|
3860
|
+
Math.ceil(
|
|
3861
|
+
(recoveryBindSent.sentAt + recoveryBindSent.cooldownSec * 1e3 - Date.now()) / 1e3
|
|
3862
|
+
)
|
|
3863
|
+
);
|
|
3864
|
+
setBindCooldownLeft(rem);
|
|
3865
|
+
};
|
|
3866
|
+
update();
|
|
3867
|
+
const timer = window.setInterval(update, 1e3);
|
|
3868
|
+
return () => window.clearInterval(timer);
|
|
3869
|
+
}, [open, recoveryBindSent]);
|
|
3694
3870
|
if (!open) return null;
|
|
3871
|
+
const needsRecoveryBind = Boolean(
|
|
3872
|
+
mode === "set" && recovery && !recovery.hasRecovery && onRequestRecoveryEmailBind
|
|
3873
|
+
);
|
|
3695
3874
|
const mismatch = password.length > 0 && confirm.length > 0 && password !== confirm;
|
|
3696
|
-
const
|
|
3875
|
+
const normalizedCode = code.trim();
|
|
3876
|
+
const validCode = /^\d{6}$/.test(normalizedCode);
|
|
3877
|
+
const normalizedBindCode = recoveryCode.trim();
|
|
3878
|
+
const validBindCode = /^\d{6}$/.test(normalizedBindCode);
|
|
3879
|
+
const validRecoveryEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(recoveryEmail.trim());
|
|
3880
|
+
const canSet = password.length >= 6 && password === confirm && (!passwordEnabled || current.length > 0) && (!needsRecoveryBind || validRecoveryEmail && validBindCode) && !busy;
|
|
3697
3881
|
const canClear = passwordEnabled && current.length > 0 && !busy;
|
|
3882
|
+
const canResetSet = passwordEnabled && validCode && password.length >= 6 && password === confirm && !busy;
|
|
3883
|
+
const canResetClear = passwordEnabled && validCode && !busy;
|
|
3884
|
+
const resetHintText = mode === "reset" && resetSent ? (resetSent.channel === "telegram" ? labels.passwordSettingsCodeSentTelegram : labels.passwordSettingsCodeSentEmail).replace("{target}", resetSent.maskedTarget) : mode === "reset" ? labels.passwordSettingsResetHint : needsRecoveryBind ? recoveryBindSent ? labels.passwordSettingsCodeSentEmail.replace("{target}", recoveryBindSent.maskedTarget) : labels.passwordSettingsBindEmailHint : passwordEnabled ? labels.passwordSettingsEnabledHint : labels.passwordSettingsDisabledHint;
|
|
3885
|
+
const dualChannels = Boolean(recovery?.channels && recovery.channels.length > 1);
|
|
3886
|
+
const effectiveResetChannel = selectedChannel ?? recovery?.defaultChannel ?? void 0;
|
|
3698
3887
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
3699
3888
|
/* @__PURE__ */ jsx("div", { className: "auth-sdk-backdrop", onClick: busy ? void 0 : onClose, "aria-hidden": true }),
|
|
3700
3889
|
/* @__PURE__ */ jsxs(
|
|
@@ -3712,7 +3901,7 @@ function SetPasswordModal({
|
|
|
3712
3901
|
/* @__PURE__ */ jsx("h2", { id: "auth-sdk-password-title", className: "auth-sdk-sign-title", children: labels.passwordSettingsTitle })
|
|
3713
3902
|
] })
|
|
3714
3903
|
] }),
|
|
3715
|
-
/* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-subtitle", children:
|
|
3904
|
+
/* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-subtitle", children: resetHintText }),
|
|
3716
3905
|
passwordEnabled ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-mode-tabs", role: "tablist", children: [
|
|
3717
3906
|
/* @__PURE__ */ jsx(
|
|
3718
3907
|
"button",
|
|
@@ -3737,14 +3926,87 @@ function SetPasswordModal({
|
|
|
3737
3926
|
disabled: busy,
|
|
3738
3927
|
children: labels.passwordSettingsClear
|
|
3739
3928
|
}
|
|
3740
|
-
)
|
|
3929
|
+
),
|
|
3930
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
3931
|
+
"button",
|
|
3932
|
+
{
|
|
3933
|
+
type: "button",
|
|
3934
|
+
role: "tab",
|
|
3935
|
+
className: `auth-sdk-mode-tab${mode === "reset" ? " is-active" : ""}`,
|
|
3936
|
+
"aria-selected": mode === "reset",
|
|
3937
|
+
onClick: () => setMode("reset"),
|
|
3938
|
+
disabled: busy,
|
|
3939
|
+
children: labels.passwordSettingsReset
|
|
3940
|
+
}
|
|
3941
|
+
) : null
|
|
3741
3942
|
] }) : null,
|
|
3742
3943
|
mode === "set" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3743
|
-
|
|
3744
|
-
/* @__PURE__ */
|
|
3944
|
+
needsRecoveryBind ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3945
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
3946
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsBindEmailLabel }),
|
|
3947
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
|
|
3948
|
+
/* @__PURE__ */ jsx(
|
|
3949
|
+
"input",
|
|
3950
|
+
{
|
|
3951
|
+
type: "email",
|
|
3952
|
+
autoComplete: "email",
|
|
3953
|
+
placeholder: labels.passwordSettingsBindEmailPlaceholder,
|
|
3954
|
+
value: recoveryEmail,
|
|
3955
|
+
onChange: (e) => setRecoveryEmail(e.target.value),
|
|
3956
|
+
disabled: busy,
|
|
3957
|
+
autoFocus: !passwordEnabled
|
|
3958
|
+
}
|
|
3959
|
+
),
|
|
3960
|
+
/* @__PURE__ */ jsx(
|
|
3961
|
+
"button",
|
|
3962
|
+
{
|
|
3963
|
+
type: "button",
|
|
3964
|
+
className: "auth-sdk-code-send-btn",
|
|
3965
|
+
disabled: busy || sendingRecoveryBindCode || bindCooldownLeft > 0 || !validRecoveryEmail,
|
|
3966
|
+
onClick: () => void onRequestRecoveryEmailBind?.(recoveryEmail.trim()),
|
|
3967
|
+
children: sendingRecoveryBindCode ? labels.passwordSettingsSendingCode : bindCooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
|
|
3968
|
+
"{seconds}",
|
|
3969
|
+
String(bindCooldownLeft)
|
|
3970
|
+
) : recoveryBindSent ? labels.passwordSettingsResendCode : labels.passwordSettingsSendCode
|
|
3971
|
+
}
|
|
3972
|
+
)
|
|
3973
|
+
] })
|
|
3974
|
+
] }),
|
|
3975
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
3976
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
|
|
3977
|
+
/* @__PURE__ */ jsx(
|
|
3978
|
+
"input",
|
|
3979
|
+
{
|
|
3980
|
+
type: "text",
|
|
3981
|
+
inputMode: "numeric",
|
|
3982
|
+
maxLength: 6,
|
|
3983
|
+
autoComplete: "one-time-code",
|
|
3984
|
+
placeholder: labels.passwordSettingsCodePlaceholder,
|
|
3985
|
+
value: recoveryCode,
|
|
3986
|
+
onChange: (e) => setRecoveryCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
|
|
3987
|
+
disabled: busy
|
|
3988
|
+
}
|
|
3989
|
+
)
|
|
3990
|
+
] })
|
|
3991
|
+
] }) : null,
|
|
3992
|
+
passwordEnabled ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
3993
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
3994
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-pw-current", children: labels.passwordSettingsCurrentLabel }),
|
|
3995
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
3996
|
+
"button",
|
|
3997
|
+
{
|
|
3998
|
+
type: "button",
|
|
3999
|
+
className: "auth-sdk-forgot-btn",
|
|
4000
|
+
onClick: () => setMode("reset"),
|
|
4001
|
+
disabled: busy,
|
|
4002
|
+
children: labels.signForgotPassword
|
|
4003
|
+
}
|
|
4004
|
+
) : null
|
|
4005
|
+
] }),
|
|
3745
4006
|
/* @__PURE__ */ jsx(
|
|
3746
4007
|
"input",
|
|
3747
4008
|
{
|
|
4009
|
+
id: "auth-sdk-pw-current",
|
|
3748
4010
|
type: "password",
|
|
3749
4011
|
autoComplete: "current-password",
|
|
3750
4012
|
placeholder: labels.passwordSettingsCurrentPlaceholder,
|
|
@@ -3766,7 +4028,7 @@ function SetPasswordModal({
|
|
|
3766
4028
|
value: password,
|
|
3767
4029
|
onChange: (e) => setPassword(e.target.value),
|
|
3768
4030
|
disabled: busy,
|
|
3769
|
-
autoFocus: !passwordEnabled
|
|
4031
|
+
autoFocus: !passwordEnabled && !needsRecoveryBind
|
|
3770
4032
|
}
|
|
3771
4033
|
)
|
|
3772
4034
|
] }),
|
|
@@ -3785,11 +4047,24 @@ function SetPasswordModal({
|
|
|
3785
4047
|
)
|
|
3786
4048
|
] }),
|
|
3787
4049
|
mismatch ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: labels.passwordSettingsMismatch }) : null
|
|
3788
|
-
] }) : /* @__PURE__ */ jsxs("
|
|
3789
|
-
/* @__PURE__ */
|
|
4050
|
+
] }) : mode === "clear" ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4051
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
4052
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-pw-clear-current", children: labels.passwordSettingsCurrentLabel }),
|
|
4053
|
+
onRequestResetCode && onSubmitReset ? /* @__PURE__ */ jsx(
|
|
4054
|
+
"button",
|
|
4055
|
+
{
|
|
4056
|
+
type: "button",
|
|
4057
|
+
className: "auth-sdk-forgot-btn",
|
|
4058
|
+
onClick: () => setMode("reset"),
|
|
4059
|
+
disabled: busy,
|
|
4060
|
+
children: labels.signForgotPassword
|
|
4061
|
+
}
|
|
4062
|
+
) : null
|
|
4063
|
+
] }),
|
|
3790
4064
|
/* @__PURE__ */ jsx(
|
|
3791
4065
|
"input",
|
|
3792
4066
|
{
|
|
4067
|
+
id: "auth-sdk-pw-clear-current",
|
|
3793
4068
|
type: "password",
|
|
3794
4069
|
autoComplete: "current-password",
|
|
3795
4070
|
placeholder: labels.passwordSettingsCurrentPlaceholder,
|
|
@@ -3799,6 +4074,103 @@ function SetPasswordModal({
|
|
|
3799
4074
|
autoFocus: true
|
|
3800
4075
|
}
|
|
3801
4076
|
)
|
|
4077
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4078
|
+
dualChannels ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-mode-tabs", role: "radiogroup", children: [
|
|
4079
|
+
/* @__PURE__ */ jsxs(
|
|
4080
|
+
"button",
|
|
4081
|
+
{
|
|
4082
|
+
type: "button",
|
|
4083
|
+
className: `auth-sdk-mode-tab${effectiveResetChannel === "email" ? " is-active" : ""}`,
|
|
4084
|
+
onClick: () => setSelectedChannel("email"),
|
|
4085
|
+
disabled: busy || sendingResetCode,
|
|
4086
|
+
children: [
|
|
4087
|
+
"Email",
|
|
4088
|
+
recovery?.maskedEmail ? ` (${recovery.maskedEmail})` : ""
|
|
4089
|
+
]
|
|
4090
|
+
}
|
|
4091
|
+
),
|
|
4092
|
+
/* @__PURE__ */ jsx(
|
|
4093
|
+
"button",
|
|
4094
|
+
{
|
|
4095
|
+
type: "button",
|
|
4096
|
+
className: `auth-sdk-mode-tab${effectiveResetChannel === "telegram" ? " is-active" : ""}`,
|
|
4097
|
+
onClick: () => setSelectedChannel("telegram"),
|
|
4098
|
+
disabled: busy || sendingResetCode,
|
|
4099
|
+
children: recovery?.maskedTelegram ?? "Telegram"
|
|
4100
|
+
}
|
|
4101
|
+
)
|
|
4102
|
+
] }) : null,
|
|
4103
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4104
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
|
|
4105
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
|
|
4106
|
+
/* @__PURE__ */ jsx(
|
|
4107
|
+
"input",
|
|
4108
|
+
{
|
|
4109
|
+
type: "text",
|
|
4110
|
+
inputMode: "numeric",
|
|
4111
|
+
maxLength: 6,
|
|
4112
|
+
autoComplete: "one-time-code",
|
|
4113
|
+
placeholder: labels.passwordSettingsCodePlaceholder,
|
|
4114
|
+
value: code,
|
|
4115
|
+
onChange: (e) => setCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
|
|
4116
|
+
disabled: busy,
|
|
4117
|
+
autoFocus: true
|
|
4118
|
+
}
|
|
4119
|
+
),
|
|
4120
|
+
/* @__PURE__ */ jsx(
|
|
4121
|
+
"button",
|
|
4122
|
+
{
|
|
4123
|
+
type: "button",
|
|
4124
|
+
className: "auth-sdk-code-send-btn",
|
|
4125
|
+
disabled: busy || sendingResetCode || cooldownLeft > 0,
|
|
4126
|
+
onClick: () => void onRequestResetCode?.(effectiveResetChannel),
|
|
4127
|
+
children: sendingResetCode ? labels.passwordSettingsSendingCode : cooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
|
|
4128
|
+
"{seconds}",
|
|
4129
|
+
String(cooldownLeft)
|
|
4130
|
+
) : resetSent ? labels.passwordSettingsResendCode : labels.passwordSettingsSendCode
|
|
4131
|
+
}
|
|
4132
|
+
)
|
|
4133
|
+
] })
|
|
4134
|
+
] }),
|
|
4135
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4136
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsNewLabel }),
|
|
4137
|
+
/* @__PURE__ */ jsx(
|
|
4138
|
+
"input",
|
|
4139
|
+
{
|
|
4140
|
+
type: "password",
|
|
4141
|
+
autoComplete: "new-password",
|
|
4142
|
+
placeholder: labels.passwordSettingsNewPlaceholder,
|
|
4143
|
+
value: password,
|
|
4144
|
+
onChange: (e) => setPassword(e.target.value),
|
|
4145
|
+
disabled: busy
|
|
4146
|
+
}
|
|
4147
|
+
)
|
|
4148
|
+
] }),
|
|
4149
|
+
/* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
|
|
4150
|
+
/* @__PURE__ */ jsx("span", { children: labels.passwordSettingsConfirmLabel }),
|
|
4151
|
+
/* @__PURE__ */ jsx(
|
|
4152
|
+
"input",
|
|
4153
|
+
{
|
|
4154
|
+
type: "password",
|
|
4155
|
+
autoComplete: "new-password",
|
|
4156
|
+
placeholder: labels.passwordSettingsConfirmPlaceholder,
|
|
4157
|
+
value: confirm,
|
|
4158
|
+
onChange: (e) => setConfirm(e.target.value),
|
|
4159
|
+
disabled: busy
|
|
4160
|
+
}
|
|
4161
|
+
)
|
|
4162
|
+
] }),
|
|
4163
|
+
mismatch ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: labels.passwordSettingsMismatch }) : null,
|
|
4164
|
+
validCode && password.length === 0 ? /* @__PURE__ */ jsx("div", { className: "auth-sdk-reset-clear-row", children: /* @__PURE__ */ jsx(
|
|
4165
|
+
"button",
|
|
4166
|
+
{
|
|
4167
|
+
type: "button",
|
|
4168
|
+
className: "auth-sdk-forgot-btn",
|
|
4169
|
+
disabled: !canResetClear,
|
|
4170
|
+
onClick: () => void onSubmitReset?.(normalizedCode, null),
|
|
4171
|
+
children: labels.passwordSettingsResetClearConfirm
|
|
4172
|
+
}
|
|
4173
|
+
) }) : null
|
|
3802
4174
|
] }),
|
|
3803
4175
|
error ? /* @__PURE__ */ jsx("p", { className: "auth-sdk-sign-error", children: error }) : null,
|
|
3804
4176
|
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-actions", children: [
|
|
@@ -3818,10 +4190,14 @@ function SetPasswordModal({
|
|
|
3818
4190
|
type: "button",
|
|
3819
4191
|
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
3820
4192
|
disabled: !canSet,
|
|
3821
|
-
onClick: () => void onSubmitSet(
|
|
4193
|
+
onClick: () => void onSubmitSet(
|
|
4194
|
+
password,
|
|
4195
|
+
passwordEnabled ? current : void 0,
|
|
4196
|
+
needsRecoveryBind ? { recoveryEmail: recoveryEmail.trim(), recoveryCode: normalizedBindCode } : void 0
|
|
4197
|
+
),
|
|
3822
4198
|
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsSave
|
|
3823
4199
|
}
|
|
3824
|
-
) : /* @__PURE__ */ jsx(
|
|
4200
|
+
) : mode === "clear" ? /* @__PURE__ */ jsx(
|
|
3825
4201
|
"button",
|
|
3826
4202
|
{
|
|
3827
4203
|
type: "button",
|
|
@@ -3830,6 +4206,15 @@ function SetPasswordModal({
|
|
|
3830
4206
|
onClick: () => void onSubmitClear(current),
|
|
3831
4207
|
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsClearConfirm
|
|
3832
4208
|
}
|
|
4209
|
+
) : /* @__PURE__ */ jsx(
|
|
4210
|
+
"button",
|
|
4211
|
+
{
|
|
4212
|
+
type: "button",
|
|
4213
|
+
className: "auth-sdk-btn auth-sdk-btn-primary",
|
|
4214
|
+
disabled: !canResetSet,
|
|
4215
|
+
onClick: () => void onSubmitReset?.(normalizedCode, password),
|
|
4216
|
+
children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsResetConfirm
|
|
4217
|
+
}
|
|
3833
4218
|
)
|
|
3834
4219
|
] })
|
|
3835
4220
|
]
|
|
@@ -3863,7 +4248,8 @@ function SignConfirmModal({
|
|
|
3863
4248
|
onPasswordChange,
|
|
3864
4249
|
onApprove,
|
|
3865
4250
|
onReject,
|
|
3866
|
-
onOpenSetPassword
|
|
4251
|
+
onOpenSetPassword,
|
|
4252
|
+
onOpenResetPassword
|
|
3867
4253
|
}) {
|
|
3868
4254
|
if (!open || !request) return null;
|
|
3869
4255
|
const isTyped = request.method === "eth_signTypedData_v4";
|
|
@@ -3872,6 +4258,7 @@ function SignConfirmModal({
|
|
|
3872
4258
|
const payloadLabel = isTyped ? labels.signPayloadLabelTyped : isTx ? labels.signPayloadLabelTx : labels.signPayloadLabel;
|
|
3873
4259
|
const needsPassword = request.passwordEnabled;
|
|
3874
4260
|
const canApprove = !locked && (needsPassword ? password.length > 0 && !busy : !busy);
|
|
4261
|
+
const handleForgotPassword = onOpenResetPassword ?? onOpenSetPassword;
|
|
3875
4262
|
return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
|
|
3876
4263
|
/* @__PURE__ */ jsx("div", { className: "auth-sdk-backdrop", onClick: busy ? void 0 : onReject, "aria-hidden": true }),
|
|
3877
4264
|
/* @__PURE__ */ jsxs(
|
|
@@ -3904,11 +4291,24 @@ function SignConfirmModal({
|
|
|
3904
4291
|
/* @__PURE__ */ jsx("span", { className: "auth-sdk-sign-msg-label", children: payloadLabel }),
|
|
3905
4292
|
/* @__PURE__ */ jsx("pre", { className: "auth-sdk-sign-body", children: truncateMessage(request.message) })
|
|
3906
4293
|
] }),
|
|
3907
|
-
needsPassword ? /* @__PURE__ */ jsxs("
|
|
3908
|
-
/* @__PURE__ */
|
|
4294
|
+
needsPassword ? /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
|
|
4295
|
+
/* @__PURE__ */ jsxs("div", { className: "auth-sdk-password-label-row", children: [
|
|
4296
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "auth-sdk-sign-password-input", children: labels.signPasswordLabel }),
|
|
4297
|
+
handleForgotPassword ? /* @__PURE__ */ jsx(
|
|
4298
|
+
"button",
|
|
4299
|
+
{
|
|
4300
|
+
type: "button",
|
|
4301
|
+
className: "auth-sdk-forgot-btn",
|
|
4302
|
+
onClick: handleForgotPassword,
|
|
4303
|
+
disabled: busy,
|
|
4304
|
+
children: labels.signForgotPassword
|
|
4305
|
+
}
|
|
4306
|
+
) : null
|
|
4307
|
+
] }),
|
|
3909
4308
|
/* @__PURE__ */ jsx(
|
|
3910
4309
|
"input",
|
|
3911
4310
|
{
|
|
4311
|
+
id: "auth-sdk-sign-password-input",
|
|
3912
4312
|
type: "password",
|
|
3913
4313
|
autoComplete: "current-password",
|
|
3914
4314
|
placeholder: labels.signPasswordPlaceholder,
|
|
@@ -3980,6 +4380,7 @@ var DEFAULT_LABELS = {
|
|
|
3980
4380
|
signReject: "Reject",
|
|
3981
4381
|
signPasswordLabel: "Wallet password",
|
|
3982
4382
|
signPasswordPlaceholder: "Enter password",
|
|
4383
|
+
signForgotPassword: "Forgot password?",
|
|
3983
4384
|
signSetPasswordOptional: "Optional \u2014 protect future signatures with a password.",
|
|
3984
4385
|
signSetPasswordButton: "Set password",
|
|
3985
4386
|
signPasswordIncorrect: "Incorrect password",
|
|
@@ -4010,6 +4411,29 @@ var DEFAULT_LABELS = {
|
|
|
4010
4411
|
passwordSettingsDisabledHint: "Optional. When set, signing will ask for this password.",
|
|
4011
4412
|
passwordSettingsChange: "Change",
|
|
4012
4413
|
passwordSettingsClear: "Remove",
|
|
4414
|
+
passwordSettingsReset: "Reset",
|
|
4415
|
+
passwordSettingsResetHint: "Receive a 6-digit verification code via your bound email or Telegram to reset your wallet password.",
|
|
4416
|
+
passwordSettingsSendCode: "Send code",
|
|
4417
|
+
passwordSettingsSendingCode: "Sending\u2026",
|
|
4418
|
+
passwordSettingsResendCode: "Resend",
|
|
4419
|
+
passwordSettingsResendCooldown: "Resend ({seconds}s)",
|
|
4420
|
+
passwordSettingsCodeSentEmail: "Verification code sent to {target}",
|
|
4421
|
+
passwordSettingsCodeSentTelegram: "Verification code sent via {target}",
|
|
4422
|
+
passwordSettingsCodeLabel: "Verification code",
|
|
4423
|
+
passwordSettingsCodePlaceholder: "6-digit code",
|
|
4424
|
+
passwordSettingsResetConfirm: "Reset password",
|
|
4425
|
+
passwordSettingsResetClearConfirm: "Verify & remove password",
|
|
4426
|
+
passwordSettingsResetCodeInvalid: "Incorrect verification code",
|
|
4427
|
+
passwordSettingsResetCodeExpired: "Verification code expired. Please request a new code.",
|
|
4428
|
+
passwordSettingsResetCodeLocked: "Too many incorrect attempts. Please request a new code.",
|
|
4429
|
+
passwordSettingsResetCooldown: "Please wait {seconds}s before requesting another code.",
|
|
4430
|
+
passwordSettingsResetChannelUnavailable: "No verified email or Telegram account is linked to this wallet.",
|
|
4431
|
+
passwordSettingsResetDeliveryFailed: "Failed to send verification code. Please try again.",
|
|
4432
|
+
passwordSettingsBindEmailLabel: "Recovery email",
|
|
4433
|
+
passwordSettingsBindEmailPlaceholder: "Enter email for password recovery",
|
|
4434
|
+
passwordSettingsBindEmailHint: "Your login method has no email or Telegram linked. Verify a recovery email to enable wallet password.",
|
|
4435
|
+
passwordSettingsRecoveryRequired: "Please verify a recovery email first",
|
|
4436
|
+
passwordSettingsInvalidRecoveryEmail: "Please enter a valid email address",
|
|
4013
4437
|
passwordSettingsCurrentLabel: "Current password",
|
|
4014
4438
|
passwordSettingsCurrentPlaceholder: "Current password",
|
|
4015
4439
|
passwordSettingsNewLabel: "New password",
|
|
@@ -4042,8 +4466,14 @@ function AuthProvider({
|
|
|
4042
4466
|
const [signBusy, setSignBusy] = useState(false);
|
|
4043
4467
|
const [signError, setSignError] = useState(null);
|
|
4044
4468
|
const [passwordSettingsOpen, setPasswordSettingsOpen] = useState(false);
|
|
4469
|
+
const [passwordInitialMode, setPasswordInitialMode] = useState("set");
|
|
4045
4470
|
const [passwordBusy, setPasswordBusy] = useState(false);
|
|
4471
|
+
const [sendingResetCode, setSendingResetCode] = useState(false);
|
|
4472
|
+
const [resetSent, setResetSent] = useState(null);
|
|
4473
|
+
const [sendingRecoveryBindCode, setSendingRecoveryBindCode] = useState(false);
|
|
4474
|
+
const [recoveryBindSent, setRecoveryBindSent] = useState(null);
|
|
4046
4475
|
const [passwordError, setPasswordError] = useState(null);
|
|
4476
|
+
const [passwordVersion, setPasswordVersion] = useState(0);
|
|
4047
4477
|
const pendingSignRef = useRef(null);
|
|
4048
4478
|
const defaultModalApproval = useCallback((req) => {
|
|
4049
4479
|
return new Promise((resolve) => {
|
|
@@ -4198,8 +4628,9 @@ function AuthProvider({
|
|
|
4198
4628
|
const getProvider = useCallback(() => clientRef.current.getProvider(), []);
|
|
4199
4629
|
const getConnectorShim = useCallback(() => clientRef.current.getConnectorShim(), []);
|
|
4200
4630
|
const setPassword = useCallback(
|
|
4201
|
-
async (pw, currentPassword) => {
|
|
4202
|
-
await clientRef.current.setPassword(pw, currentPassword);
|
|
4631
|
+
async (pw, currentPassword, recoveryBind) => {
|
|
4632
|
+
await clientRef.current.setPassword(pw, currentPassword, recoveryBind);
|
|
4633
|
+
setPasswordVersion((v) => v + 1);
|
|
4203
4634
|
bump();
|
|
4204
4635
|
},
|
|
4205
4636
|
[bump]
|
|
@@ -4207,19 +4638,47 @@ function AuthProvider({
|
|
|
4207
4638
|
const clearPassword = useCallback(
|
|
4208
4639
|
async (pw) => {
|
|
4209
4640
|
await clientRef.current.clearPassword(pw);
|
|
4641
|
+
setPasswordVersion((v) => v + 1);
|
|
4642
|
+
bump();
|
|
4643
|
+
},
|
|
4644
|
+
[bump]
|
|
4645
|
+
);
|
|
4646
|
+
const requestPasswordReset = useCallback(
|
|
4647
|
+
async (channel) => {
|
|
4648
|
+
return clientRef.current.requestPasswordReset(channel);
|
|
4649
|
+
},
|
|
4650
|
+
[]
|
|
4651
|
+
);
|
|
4652
|
+
const confirmPasswordReset = useCallback(
|
|
4653
|
+
async (code, newPassword) => {
|
|
4654
|
+
const out = await clientRef.current.confirmPasswordReset(code, newPassword);
|
|
4655
|
+
setPasswordVersion((v) => v + 1);
|
|
4210
4656
|
bump();
|
|
4657
|
+
return out;
|
|
4211
4658
|
},
|
|
4212
4659
|
[bump]
|
|
4213
4660
|
);
|
|
4214
|
-
const
|
|
4661
|
+
const requestRecoveryEmailBind = useCallback(async (email) => {
|
|
4662
|
+
return clientRef.current.requestRecoveryEmailBind(email);
|
|
4663
|
+
}, []);
|
|
4664
|
+
const confirmRecoveryEmailBind = useCallback(
|
|
4665
|
+
async (code, email) => {
|
|
4666
|
+
const out = await clientRef.current.confirmRecoveryEmailBind(code, email);
|
|
4667
|
+
bump();
|
|
4668
|
+
return out;
|
|
4669
|
+
},
|
|
4670
|
+
[bump]
|
|
4671
|
+
);
|
|
4672
|
+
const openPasswordSettings = useCallback((initialMode) => {
|
|
4215
4673
|
setPasswordError(null);
|
|
4674
|
+
setPasswordInitialMode(initialMode ?? "set");
|
|
4216
4675
|
setPasswordSettingsOpen(true);
|
|
4217
4676
|
}, []);
|
|
4218
4677
|
const closePasswordSettings = useCallback(() => {
|
|
4219
|
-
if (passwordBusy) return;
|
|
4678
|
+
if (passwordBusy || sendingResetCode || sendingRecoveryBindCode) return;
|
|
4220
4679
|
setPasswordSettingsOpen(false);
|
|
4221
4680
|
setPasswordError(null);
|
|
4222
|
-
}, [passwordBusy]);
|
|
4681
|
+
}, [passwordBusy, sendingResetCode, sendingRecoveryBindCode]);
|
|
4223
4682
|
const client = clientRef.current;
|
|
4224
4683
|
const authenticated = client.isAuthenticated();
|
|
4225
4684
|
const user = client.getUser();
|
|
@@ -4248,12 +4707,12 @@ function AuthProvider({
|
|
|
4248
4707
|
}
|
|
4249
4708
|
resolvePending({ approved: true });
|
|
4250
4709
|
}, [signBusy, password, resolvePending]);
|
|
4251
|
-
const
|
|
4710
|
+
const markPendingSignPasswordState = useCallback((enabled) => {
|
|
4252
4711
|
const entry = pendingSignRef.current;
|
|
4253
4712
|
if (!entry) return;
|
|
4254
4713
|
const next = {
|
|
4255
4714
|
...entry,
|
|
4256
|
-
request: { ...entry.request, passwordEnabled:
|
|
4715
|
+
request: { ...entry.request, passwordEnabled: enabled, authError: void 0 }
|
|
4257
4716
|
};
|
|
4258
4717
|
pendingSignRef.current = next;
|
|
4259
4718
|
setPendingSign(next);
|
|
@@ -4275,23 +4734,45 @@ function AuthProvider({
|
|
|
4275
4734
|
if (signBusy) return;
|
|
4276
4735
|
resolvePending(false);
|
|
4277
4736
|
},
|
|
4278
|
-
onOpenSetPassword: openPasswordSettings
|
|
4737
|
+
onOpenSetPassword: () => openPasswordSettings("set"),
|
|
4738
|
+
onOpenResetPassword: () => openPasswordSettings("reset")
|
|
4279
4739
|
};
|
|
4280
4740
|
const onSubmitSet = useCallback(
|
|
4281
|
-
async (pw, currentPassword) => {
|
|
4741
|
+
async (pw, currentPassword, recoveryBind) => {
|
|
4282
4742
|
setPasswordBusy(true);
|
|
4283
4743
|
setPasswordError(null);
|
|
4284
4744
|
try {
|
|
4285
|
-
await setPassword(pw, currentPassword);
|
|
4745
|
+
await setPassword(pw, currentPassword, recoveryBind);
|
|
4746
|
+
setRecoveryBindSent(null);
|
|
4286
4747
|
setPasswordSettingsOpen(false);
|
|
4287
|
-
if (pendingSignRef.current)
|
|
4748
|
+
if (pendingSignRef.current) markPendingSignPasswordState(true);
|
|
4288
4749
|
} catch (e) {
|
|
4289
4750
|
setPasswordError(formatAuthError(e, labels));
|
|
4290
4751
|
} finally {
|
|
4291
4752
|
setPasswordBusy(false);
|
|
4292
4753
|
}
|
|
4293
4754
|
},
|
|
4294
|
-
[setPassword,
|
|
4755
|
+
[setPassword, markPendingSignPasswordState, labels]
|
|
4756
|
+
);
|
|
4757
|
+
const onRequestRecoveryEmailBind = useCallback(
|
|
4758
|
+
async (email) => {
|
|
4759
|
+
setSendingRecoveryBindCode(true);
|
|
4760
|
+
setPasswordError(null);
|
|
4761
|
+
try {
|
|
4762
|
+
const out = await requestRecoveryEmailBind(email);
|
|
4763
|
+
setRecoveryBindSent({
|
|
4764
|
+
channel: "email",
|
|
4765
|
+
maskedTarget: out.maskedTarget,
|
|
4766
|
+
cooldownSec: out.cooldownSec,
|
|
4767
|
+
sentAt: Date.now()
|
|
4768
|
+
});
|
|
4769
|
+
} catch (e) {
|
|
4770
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4771
|
+
} finally {
|
|
4772
|
+
setSendingRecoveryBindCode(false);
|
|
4773
|
+
}
|
|
4774
|
+
},
|
|
4775
|
+
[requestRecoveryEmailBind, labels]
|
|
4295
4776
|
);
|
|
4296
4777
|
const onSubmitClear = useCallback(
|
|
4297
4778
|
async (pw) => {
|
|
@@ -4300,22 +4781,69 @@ function AuthProvider({
|
|
|
4300
4781
|
try {
|
|
4301
4782
|
await clearPassword(pw);
|
|
4302
4783
|
setPasswordSettingsOpen(false);
|
|
4784
|
+
if (pendingSignRef.current) markPendingSignPasswordState(false);
|
|
4785
|
+
} catch (e) {
|
|
4786
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4787
|
+
} finally {
|
|
4788
|
+
setPasswordBusy(false);
|
|
4789
|
+
}
|
|
4790
|
+
},
|
|
4791
|
+
[clearPassword, markPendingSignPasswordState, labels]
|
|
4792
|
+
);
|
|
4793
|
+
const onRequestResetCode = useCallback(
|
|
4794
|
+
async (channel) => {
|
|
4795
|
+
setSendingResetCode(true);
|
|
4796
|
+
setPasswordError(null);
|
|
4797
|
+
try {
|
|
4798
|
+
const out = await requestPasswordReset(channel);
|
|
4799
|
+
setResetSent({
|
|
4800
|
+
channel: out.channel,
|
|
4801
|
+
maskedTarget: out.maskedTarget,
|
|
4802
|
+
cooldownSec: out.cooldownSec,
|
|
4803
|
+
sentAt: Date.now()
|
|
4804
|
+
});
|
|
4805
|
+
} catch (e) {
|
|
4806
|
+
setPasswordError(formatAuthError(e, labels));
|
|
4807
|
+
} finally {
|
|
4808
|
+
setSendingResetCode(false);
|
|
4809
|
+
}
|
|
4810
|
+
},
|
|
4811
|
+
[requestPasswordReset, labels]
|
|
4812
|
+
);
|
|
4813
|
+
const onSubmitReset = useCallback(
|
|
4814
|
+
async (code, newPassword) => {
|
|
4815
|
+
setPasswordBusy(true);
|
|
4816
|
+
setPasswordError(null);
|
|
4817
|
+
try {
|
|
4818
|
+
const out = await confirmPasswordReset(code, newPassword);
|
|
4819
|
+
setResetSent(null);
|
|
4820
|
+
setPasswordSettingsOpen(false);
|
|
4821
|
+
if (pendingSignRef.current) markPendingSignPasswordState(out.passwordEnabled);
|
|
4303
4822
|
} catch (e) {
|
|
4304
4823
|
setPasswordError(formatAuthError(e, labels));
|
|
4305
4824
|
} finally {
|
|
4306
4825
|
setPasswordBusy(false);
|
|
4307
4826
|
}
|
|
4308
4827
|
},
|
|
4309
|
-
[
|
|
4828
|
+
[confirmPasswordReset, markPendingSignPasswordState, labels]
|
|
4310
4829
|
);
|
|
4311
4830
|
const passwordProps = {
|
|
4312
4831
|
open: passwordSettingsOpen,
|
|
4313
4832
|
passwordEnabled,
|
|
4833
|
+
initialMode: passwordInitialMode,
|
|
4834
|
+
recovery: user?.recovery ?? null,
|
|
4314
4835
|
labels,
|
|
4315
4836
|
busy: passwordBusy,
|
|
4837
|
+
sendingResetCode,
|
|
4838
|
+
resetSent,
|
|
4839
|
+
sendingRecoveryBindCode,
|
|
4840
|
+
recoveryBindSent,
|
|
4316
4841
|
error: passwordError,
|
|
4317
4842
|
onSubmitSet,
|
|
4318
4843
|
onSubmitClear,
|
|
4844
|
+
onRequestResetCode,
|
|
4845
|
+
onSubmitReset,
|
|
4846
|
+
onRequestRecoveryEmailBind,
|
|
4319
4847
|
onClose: closePasswordSettings
|
|
4320
4848
|
};
|
|
4321
4849
|
const value = useMemo(
|
|
@@ -4325,6 +4853,7 @@ function AuthProvider({
|
|
|
4325
4853
|
address,
|
|
4326
4854
|
user,
|
|
4327
4855
|
passwordEnabled,
|
|
4856
|
+
passwordVersion,
|
|
4328
4857
|
login,
|
|
4329
4858
|
loginTelegramMiniApp,
|
|
4330
4859
|
logout,
|
|
@@ -4337,6 +4866,10 @@ function AuthProvider({
|
|
|
4337
4866
|
getConnectorShim,
|
|
4338
4867
|
setPassword,
|
|
4339
4868
|
clearPassword,
|
|
4869
|
+
requestPasswordReset,
|
|
4870
|
+
confirmPasswordReset,
|
|
4871
|
+
requestRecoveryEmailBind,
|
|
4872
|
+
confirmRecoveryEmailBind,
|
|
4340
4873
|
openPasswordSettings,
|
|
4341
4874
|
closePasswordSettings,
|
|
4342
4875
|
client,
|
|
@@ -4350,6 +4883,7 @@ function AuthProvider({
|
|
|
4350
4883
|
address,
|
|
4351
4884
|
user,
|
|
4352
4885
|
passwordEnabled,
|
|
4886
|
+
passwordVersion,
|
|
4353
4887
|
login,
|
|
4354
4888
|
loginTelegramMiniApp,
|
|
4355
4889
|
logout,
|
|
@@ -4362,6 +4896,10 @@ function AuthProvider({
|
|
|
4362
4896
|
getConnectorShim,
|
|
4363
4897
|
setPassword,
|
|
4364
4898
|
clearPassword,
|
|
4899
|
+
requestPasswordReset,
|
|
4900
|
+
confirmPasswordReset,
|
|
4901
|
+
requestRecoveryEmailBind,
|
|
4902
|
+
confirmRecoveryEmailBind,
|
|
4365
4903
|
openPasswordSettings,
|
|
4366
4904
|
closePasswordSettings,
|
|
4367
4905
|
client,
|