eocene-auth-sdk 0.5.0 → 0.5.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.d.ts CHANGED
@@ -67,6 +67,8 @@ type WaasPasswordResetRequestResult = {
67
67
  type WaasPasswordResetConfirmResult = {
68
68
  ok: true;
69
69
  passwordEnabled: boolean;
70
+ recoveryEmail?: string;
71
+ recovery?: WaasWalletRecoveryStatus;
70
72
  };
71
73
  type WaasRecoveryEmailBindRequestResult = {
72
74
  ok: true;
@@ -151,7 +153,7 @@ declare class WaasClient {
151
153
  requestRecoveryEmailBind(email: string): Promise<WaasRecoveryEmailBindRequestResult>;
152
154
  confirmRecoveryEmailBind(code: string, email?: string): Promise<WaasRecoveryEmailBindConfirmResult>;
153
155
  clearPassword(password: string): Promise<void>;
154
- requestPasswordReset(channel?: WaasPasswordResetChannel): Promise<WaasPasswordResetRequestResult>;
156
+ requestPasswordReset(channel?: WaasPasswordResetChannel, email?: string): Promise<WaasPasswordResetRequestResult>;
155
157
  confirmPasswordReset(code: string, newPassword?: string | null): Promise<WaasPasswordResetConfirmResult>;
156
158
  signMessage(message: string, opts?: {
157
159
  password?: string;
@@ -332,9 +334,10 @@ type PasswordSettingsProps = {
332
334
  recoveryCode?: string;
333
335
  }) => Promise<void>;
334
336
  onSubmitClear: (password: string) => Promise<void>;
335
- onRequestResetCode?: (channel?: WaasPasswordResetChannel) => Promise<void>;
337
+ onRequestResetCode?: (channel?: WaasPasswordResetChannel, email?: string) => Promise<void>;
336
338
  onSubmitReset?: (code: string, newPassword?: string | null) => Promise<void>;
337
339
  onRequestRecoveryEmailBind?: (email: string) => Promise<void>;
340
+ onConfirmRecoveryEmailBind?: (code: string, email?: string) => Promise<void>;
338
341
  onClose: () => void;
339
342
  };
340
343
  type LoginPanelProps = {
@@ -463,8 +466,9 @@ declare class AuthClient {
463
466
  clearPassword(password: string): Promise<void>;
464
467
  requestRecoveryEmailBind(email: string): Promise<WaasRecoveryEmailBindRequestResult>;
465
468
  confirmRecoveryEmailBind(code: string, email?: string): Promise<WaasRecoveryEmailBindConfirmResult>;
466
- requestPasswordReset(channel?: WaasPasswordResetChannel): Promise<WaasPasswordResetRequestResult>;
469
+ requestPasswordReset(channel?: WaasPasswordResetChannel, email?: string): Promise<WaasPasswordResetRequestResult>;
467
470
  confirmPasswordReset(code: string, newPassword?: string | null): Promise<WaasPasswordResetConfirmResult>;
471
+ refreshUser(): Promise<AuthUser | null>;
468
472
  }
469
473
 
470
474
  /**
@@ -514,7 +518,7 @@ type AuthContextValue = {
514
518
  recoveryCode?: string;
515
519
  }) => Promise<void>;
516
520
  clearPassword: (password: string) => Promise<void>;
517
- requestPasswordReset: (channel?: WaasPasswordResetChannel) => Promise<WaasPasswordResetRequestResult>;
521
+ requestPasswordReset: (channel?: WaasPasswordResetChannel, email?: string) => Promise<WaasPasswordResetRequestResult>;
518
522
  confirmPasswordReset: (code: string, newPassword?: string | null) => Promise<WaasPasswordResetConfirmResult>;
519
523
  requestRecoveryEmailBind: (email: string) => Promise<WaasRecoveryEmailBindRequestResult>;
520
524
  confirmRecoveryEmailBind: (code: string, email?: string) => Promise<WaasRecoveryEmailBindConfirmResult>;
@@ -564,7 +568,7 @@ declare function authConfigFromViteEnv(env?: object): AuthSdkConfig;
564
568
 
565
569
  declare function SignConfirmModal({ open, request, labels, password, busy, error, locked, onPasswordChange, onApprove, onReject, onOpenSetPassword, onOpenResetPassword, }: SignApprovalProps): react.JSX.Element | null;
566
570
 
567
- declare function SetPasswordModal({ open, passwordEnabled, initialMode, recovery, labels, busy, sendingResetCode, resetSent, sendingRecoveryBindCode, recoveryBindSent, error, onSubmitSet, onSubmitClear, onRequestResetCode, onSubmitReset, onRequestRecoveryEmailBind, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
571
+ declare function SetPasswordModal({ open, passwordEnabled, initialMode, recovery, labels, busy, sendingResetCode, resetSent, sendingRecoveryBindCode, recoveryBindSent, error, onSubmitSet, onSubmitClear, onRequestResetCode, onSubmitReset, onRequestRecoveryEmailBind, onConfirmRecoveryEmailBind, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
568
572
 
569
573
  /**
570
574
  * EOCENE Research mark and lockup. Inline SVG (no asset fetch); transparent
package/dist/index.js CHANGED
@@ -2983,14 +2983,17 @@ var WaasClient = class {
2983
2983
  });
2984
2984
  if (this.state) this.state.passwordEnabled = false;
2985
2985
  }
2986
- async requestPasswordReset(channel) {
2986
+ async requestPasswordReset(channel, email) {
2987
2987
  this.requireSession();
2988
+ const payload = {};
2989
+ if (channel) payload.channel = channel;
2990
+ if (email && email.trim()) payload.email = email.trim();
2988
2991
  return this.authed(
2989
2992
  `${this.controlBaseUrl}/wallet/password/reset/request`,
2990
2993
  {
2991
2994
  method: "POST",
2992
2995
  headers: { ...this.authHeaders(), "content-type": "application/json" },
2993
- body: JSON.stringify(channel ? { channel } : {})
2996
+ body: JSON.stringify(payload)
2994
2997
  }
2995
2998
  );
2996
2999
  }
@@ -3004,7 +3007,10 @@ var WaasClient = class {
3004
3007
  body: JSON.stringify({ code, newPassword })
3005
3008
  }
3006
3009
  );
3007
- if (this.state) this.state.passwordEnabled = out.passwordEnabled;
3010
+ if (this.state) {
3011
+ this.state.passwordEnabled = out.passwordEnabled;
3012
+ if (out.recovery) this.state.recovery = out.recovery;
3013
+ }
3008
3014
  return out;
3009
3015
  }
3010
3016
  async signMessage(message, opts) {
@@ -3486,14 +3492,36 @@ var AuthClient = class {
3486
3492
  this.persist();
3487
3493
  return out;
3488
3494
  }
3489
- async requestPasswordReset(channel) {
3490
- return this.client.requestPasswordReset(channel);
3495
+ async requestPasswordReset(channel, email) {
3496
+ return this.client.requestPasswordReset(channel, email);
3491
3497
  }
3492
3498
  async confirmPasswordReset(code, newPassword) {
3493
3499
  const out = await this.client.confirmPasswordReset(code, newPassword);
3494
3500
  this.persist();
3495
3501
  return out;
3496
3502
  }
3503
+ async refreshUser() {
3504
+ const s = this.client.getState();
3505
+ if (!s?.sessionToken) return null;
3506
+ try {
3507
+ const me = await this.client.fetchMe();
3508
+ const cur = this.client.getState();
3509
+ if (cur && me.wallet) {
3510
+ this.client.hydrate({
3511
+ ...cur,
3512
+ email: me.email ?? cur.email,
3513
+ walletId: me.wallet.walletId,
3514
+ address: me.wallet.address,
3515
+ epoch: me.wallet.epoch,
3516
+ passwordEnabled: me.wallet.passwordEnabled,
3517
+ recovery: me.wallet.recovery
3518
+ });
3519
+ this.persist();
3520
+ }
3521
+ } catch {
3522
+ }
3523
+ return this.getUser();
3524
+ }
3497
3525
  };
3498
3526
 
3499
3527
  // src/provider/createProvider.ts
@@ -3808,6 +3836,7 @@ function SetPasswordModal({
3808
3836
  onRequestResetCode,
3809
3837
  onSubmitReset,
3810
3838
  onRequestRecoveryEmailBind,
3839
+ onConfirmRecoveryEmailBind,
3811
3840
  onClose
3812
3841
  }) {
3813
3842
  const [password, setPassword] = useState("");
@@ -3868,9 +3897,11 @@ function SetPasswordModal({
3868
3897
  return () => window.clearInterval(timer);
3869
3898
  }, [open, recoveryBindSent]);
3870
3899
  if (!open) return null;
3900
+ const hasBoundRecovery = Boolean(recovery?.hasRecovery);
3871
3901
  const needsRecoveryBind = Boolean(
3872
- mode === "set" && recovery && !recovery.hasRecovery && onRequestRecoveryEmailBind
3902
+ mode === "set" && !hasBoundRecovery && onRequestRecoveryEmailBind
3873
3903
  );
3904
+ const needsResetEmailInput = Boolean(mode === "reset" && !hasBoundRecovery);
3874
3905
  const mismatch = password.length > 0 && confirm.length > 0 && password !== confirm;
3875
3906
  const normalizedCode = code.trim();
3876
3907
  const validCode = /^\d{6}$/.test(normalizedCode);
@@ -3878,10 +3909,11 @@ function SetPasswordModal({
3878
3909
  const validBindCode = /^\d{6}$/.test(normalizedBindCode);
3879
3910
  const validRecoveryEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(recoveryEmail.trim());
3880
3911
  const canSet = password.length >= 6 && password === confirm && (!passwordEnabled || current.length > 0) && (!needsRecoveryBind || validRecoveryEmail && validBindCode) && !busy;
3912
+ const canBindEmailOnly = needsRecoveryBind && validRecoveryEmail && validBindCode && password.length === 0 && Boolean(onConfirmRecoveryEmailBind) && !busy;
3881
3913
  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;
3914
+ const canResetSet = passwordEnabled && validCode && password.length >= 6 && password === confirm && (!needsResetEmailInput || validRecoveryEmail) && !busy;
3915
+ const canResetClear = passwordEnabled && validCode && (!needsResetEmailInput || validRecoveryEmail) && !busy;
3916
+ const resetHintText = mode === "reset" && resetSent ? (resetSent.channel === "telegram" ? labels.passwordSettingsCodeSentTelegram : labels.passwordSettingsCodeSentEmail).replace("{target}", resetSent.maskedTarget) : mode === "reset" ? needsResetEmailInput ? labels.passwordSettingsBindEmailHint : labels.passwordSettingsResetHint : needsRecoveryBind ? recoveryBindSent ? labels.passwordSettingsCodeSentEmail.replace("{target}", recoveryBindSent.maskedTarget) : labels.passwordSettingsBindEmailHint : passwordEnabled ? labels.passwordSettingsEnabledHint : labels.passwordSettingsDisabledHint;
3885
3917
  const dualChannels = Boolean(recovery?.channels && recovery.channels.length > 1);
3886
3918
  const effectiveResetChannel = selectedChannel ?? recovery?.defaultChannel ?? void 0;
3887
3919
  return /* @__PURE__ */ jsxs("div", { className: "auth-sdk-root", role: "presentation", children: [
@@ -4100,6 +4132,21 @@ function SetPasswordModal({
4100
4132
  }
4101
4133
  )
4102
4134
  ] }) : null,
4135
+ needsResetEmailInput ? /* @__PURE__ */ jsxs("label", { className: "auth-sdk-password", children: [
4136
+ /* @__PURE__ */ jsx("span", { children: labels.passwordSettingsBindEmailLabel }),
4137
+ /* @__PURE__ */ jsx(
4138
+ "input",
4139
+ {
4140
+ type: "email",
4141
+ autoComplete: "email",
4142
+ placeholder: labels.passwordSettingsBindEmailPlaceholder,
4143
+ value: recoveryEmail,
4144
+ onChange: (e) => setRecoveryEmail(e.target.value),
4145
+ disabled: busy,
4146
+ autoFocus: true
4147
+ }
4148
+ )
4149
+ ] }) : null,
4103
4150
  /* @__PURE__ */ jsxs("div", { className: "auth-sdk-password", children: [
4104
4151
  /* @__PURE__ */ jsx("span", { children: labels.passwordSettingsCodeLabel }),
4105
4152
  /* @__PURE__ */ jsxs("div", { className: "auth-sdk-code-row", children: [
@@ -4114,7 +4161,7 @@ function SetPasswordModal({
4114
4161
  value: code,
4115
4162
  onChange: (e) => setCode(e.target.value.replace(/\D+/g, "").slice(0, 6)),
4116
4163
  disabled: busy,
4117
- autoFocus: true
4164
+ autoFocus: !needsResetEmailInput
4118
4165
  }
4119
4166
  ),
4120
4167
  /* @__PURE__ */ jsx(
@@ -4122,8 +4169,11 @@ function SetPasswordModal({
4122
4169
  {
4123
4170
  type: "button",
4124
4171
  className: "auth-sdk-code-send-btn",
4125
- disabled: busy || sendingResetCode || cooldownLeft > 0,
4126
- onClick: () => void onRequestResetCode?.(effectiveResetChannel),
4172
+ disabled: busy || sendingResetCode || cooldownLeft > 0 || needsResetEmailInput && !validRecoveryEmail,
4173
+ onClick: () => void onRequestResetCode?.(
4174
+ effectiveResetChannel,
4175
+ needsResetEmailInput ? recoveryEmail.trim() : void 0
4176
+ ),
4127
4177
  children: sendingResetCode ? labels.passwordSettingsSendingCode : cooldownLeft > 0 ? labels.passwordSettingsResendCooldown.replace(
4128
4178
  "{seconds}",
4129
4179
  String(cooldownLeft)
@@ -4184,7 +4234,15 @@ function SetPasswordModal({
4184
4234
  children: labels.passwordSettingsCancel
4185
4235
  }
4186
4236
  ),
4187
- mode === "set" ? /* @__PURE__ */ jsx(
4237
+ mode === "set" ? canBindEmailOnly ? /* @__PURE__ */ jsx(
4238
+ "button",
4239
+ {
4240
+ type: "button",
4241
+ className: "auth-sdk-btn auth-sdk-btn-primary",
4242
+ onClick: () => void onConfirmRecoveryEmailBind?.(normalizedBindCode, recoveryEmail.trim()),
4243
+ children: busy ? labels.passwordSettingsSaving : labels.passwordSettingsSave
4244
+ }
4245
+ ) : /* @__PURE__ */ jsx(
4188
4246
  "button",
4189
4247
  {
4190
4248
  type: "button",
@@ -4644,8 +4702,8 @@ function AuthProvider({
4644
4702
  [bump]
4645
4703
  );
4646
4704
  const requestPasswordReset = useCallback(
4647
- async (channel) => {
4648
- return clientRef.current.requestPasswordReset(channel);
4705
+ async (channel, email) => {
4706
+ return clientRef.current.requestPasswordReset(channel, email);
4649
4707
  },
4650
4708
  []
4651
4709
  );
@@ -4669,11 +4727,15 @@ function AuthProvider({
4669
4727
  },
4670
4728
  [bump]
4671
4729
  );
4672
- const openPasswordSettings = useCallback((initialMode) => {
4673
- setPasswordError(null);
4674
- setPasswordInitialMode(initialMode ?? "set");
4675
- setPasswordSettingsOpen(true);
4676
- }, []);
4730
+ const openPasswordSettings = useCallback(
4731
+ (initialMode) => {
4732
+ setPasswordError(null);
4733
+ setPasswordInitialMode(initialMode ?? "set");
4734
+ setPasswordSettingsOpen(true);
4735
+ void clientRef.current?.refreshUser().then(() => bump());
4736
+ },
4737
+ [bump]
4738
+ );
4677
4739
  const closePasswordSettings = useCallback(() => {
4678
4740
  if (passwordBusy || sendingResetCode || sendingRecoveryBindCode) return;
4679
4741
  setPasswordSettingsOpen(false);
@@ -4774,6 +4836,22 @@ function AuthProvider({
4774
4836
  },
4775
4837
  [requestRecoveryEmailBind, labels]
4776
4838
  );
4839
+ const onConfirmRecoveryEmailBind = useCallback(
4840
+ async (code, email) => {
4841
+ setPasswordBusy(true);
4842
+ setPasswordError(null);
4843
+ try {
4844
+ await confirmRecoveryEmailBind(code, email);
4845
+ setRecoveryBindSent(null);
4846
+ setPasswordSettingsOpen(false);
4847
+ } catch (e) {
4848
+ setPasswordError(formatAuthError(e, labels));
4849
+ } finally {
4850
+ setPasswordBusy(false);
4851
+ }
4852
+ },
4853
+ [confirmRecoveryEmailBind, labels]
4854
+ );
4777
4855
  const onSubmitClear = useCallback(
4778
4856
  async (pw) => {
4779
4857
  setPasswordBusy(true);
@@ -4791,11 +4869,11 @@ function AuthProvider({
4791
4869
  [clearPassword, markPendingSignPasswordState, labels]
4792
4870
  );
4793
4871
  const onRequestResetCode = useCallback(
4794
- async (channel) => {
4872
+ async (channel, email) => {
4795
4873
  setSendingResetCode(true);
4796
4874
  setPasswordError(null);
4797
4875
  try {
4798
- const out = await requestPasswordReset(channel);
4876
+ const out = await requestPasswordReset(channel, email);
4799
4877
  setResetSent({
4800
4878
  channel: out.channel,
4801
4879
  maskedTarget: out.maskedTarget,
@@ -4844,6 +4922,7 @@ function AuthProvider({
4844
4922
  onRequestResetCode,
4845
4923
  onSubmitReset,
4846
4924
  onRequestRecoveryEmailBind,
4925
+ onConfirmRecoveryEmailBind,
4847
4926
  onClose: closePasswordSettings
4848
4927
  };
4849
4928
  const value = useMemo(