@arcblock/did-connect-react 3.3.10 → 3.4.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.
Files changed (39) hide show
  1. package/lib/Connect/assets/locale.js +4 -2
  2. package/lib/Connect/components/login-item/connect-choose-list.js +120 -114
  3. package/lib/Connect/components/login-item/connect-provider-list.js +187 -180
  4. package/lib/Connect/components/login-item/login-method-item.js +63 -47
  5. package/lib/Connect/components/login-item/passkey-login-item.js +17 -15
  6. package/lib/Connect/components/login-item/wallet-login-options.js +42 -40
  7. package/lib/Connect/connect.js +503 -0
  8. package/lib/Connect/contexts/state.js +74 -65
  9. package/lib/Connect/fallback-connect.js +53 -0
  10. package/lib/Connect/hooks/provider-list.js +45 -29
  11. package/lib/Connect/index.js +13 -502
  12. package/lib/Connect/plugins/email/list-item.js +19 -18
  13. package/lib/Connect/use-connect.js +10 -10
  14. package/lib/OAuth/context.js +3 -3
  15. package/lib/Passkey/actions.js +80 -75
  16. package/lib/Passkey/context.js +3 -3
  17. package/lib/Passkey/dialog.js +7 -7
  18. package/lib/Session/assets/did-spaces-guide-cover.svg.js +74 -98
  19. package/lib/Session/index.js +189 -189
  20. package/lib/package.json.js +1 -1
  21. package/lib/utils.js +2 -2
  22. package/package.json +8 -8
  23. package/src/Connect/assets/locale.js +2 -0
  24. package/src/Connect/components/login-item/connect-choose-list.jsx +12 -5
  25. package/src/Connect/components/login-item/connect-provider-list.jsx +11 -4
  26. package/src/Connect/components/login-item/login-method-item.jsx +24 -7
  27. package/src/Connect/components/login-item/passkey-login-item.jsx +3 -1
  28. package/src/Connect/components/login-item/wallet-login-options.jsx +3 -2
  29. package/src/Connect/connect.jsx +618 -0
  30. package/src/Connect/contexts/state.jsx +10 -0
  31. package/src/Connect/fallback-connect.jsx +47 -0
  32. package/src/Connect/hooks/provider-list.js +48 -17
  33. package/src/Connect/index.jsx +8 -605
  34. package/src/Connect/plugins/email/list-item.jsx +3 -2
  35. package/src/Connect/use-connect.jsx +1 -1
  36. package/src/Passkey/actions.jsx +5 -0
  37. package/src/Session/assets/did-spaces-guide-cover.svg +1 -128
  38. package/src/Session/index.jsx +3 -4
  39. package/src/utils.js +2 -2
@@ -1,28 +1,28 @@
1
1
  import { jsxs as q, Fragment as D, jsx as n } from "react/jsx-runtime";
2
- import { useRef as I, useEffect as F, useImperativeHandle as M } from "react";
2
+ import { useRef as I, useEffect as L, useImperativeHandle as M } from "react";
3
3
  import z from "lodash/trim";
4
4
  import e from "prop-types";
5
5
  import k from "js-cookie";
6
- import { CircularProgress as L } from "@mui/material";
6
+ import { CircularProgress as B } from "@mui/material";
7
7
  import { Icon as S } from "@iconify/react";
8
- import { getCookieOptions as B } from "@arcblock/ux/lib/Util";
8
+ import { getCookieOptions as H } from "@arcblock/ux/lib/Util";
9
9
  import { useMemoizedFn as v } from "ahooks";
10
- import H from "@iconify-icons/material-symbols/passkey-rounded";
11
- import V from "@iconify-icons/material-symbols/person-add-rounded";
12
- import $ from "lodash/noop";
13
- import { mergeSx as G } from "@arcblock/ux/lib/Util/style";
14
- import { usePasskey as K } from "./context.js";
15
- import { logger as N, getWebAuthnErrorMessage as W } from "../utils.js";
16
- import Y from "../Connect/components/login-item/login-method-item.js";
17
- import J from "./dialog.js";
10
+ import V from "@iconify-icons/material-symbols/passkey-rounded";
11
+ import $ from "@iconify-icons/material-symbols/person-add-rounded";
12
+ import G from "lodash/noop";
13
+ import { mergeSx as K } from "@arcblock/ux/lib/Util/style";
14
+ import { usePasskey as N } from "./context.js";
15
+ import { logger as W, getWebAuthnErrorMessage as Y } from "../utils.js";
16
+ import J from "../Connect/components/login-item/login-method-item.js";
17
+ import Q from "./dialog.js";
18
18
  import { VERIFY_CODE_LENGTH as w } from "./constants.js";
19
- function x({ action: d, onClick: a, title: i, state: c, dense: f = !1, icon: l, ...u }) {
19
+ function x({ action: d, onClick: c, title: s, state: f, dense: l = !1, icon: u, ...m }) {
20
20
  return /* @__PURE__ */ n(
21
- Y,
21
+ J,
22
22
  {
23
- ...u,
24
- icon: c[d] ? /* @__PURE__ */ n(
25
- L,
23
+ ...m,
24
+ icon: f[d] ? /* @__PURE__ */ n(
25
+ B,
26
26
  {
27
27
  size: "1em",
28
28
  sx: {
@@ -32,11 +32,11 @@ function x({ action: d, onClick: a, title: i, state: c, dense: f = !1, icon: l,
32
32
  }
33
33
  }
34
34
  }
35
- ) : l,
35
+ ) : u,
36
36
  iconScale: 1,
37
- title: i,
38
- onClick: a,
39
- sx: G(f ? { p: 1, backgroundColor: "transparent" } : {}, u?.sx)
37
+ title: s,
38
+ onClick: c,
39
+ sx: K(l ? { p: 1, backgroundColor: "transparent" } : {}, m?.sx)
40
40
  }
41
41
  );
42
42
  }
@@ -48,104 +48,108 @@ x.propTypes = {
48
48
  dense: e.bool,
49
49
  icon: e.any.isRequired
50
50
  };
51
- function Q({
51
+ function U({
52
52
  ref: d = null,
53
- action: a,
54
- behavior: i = "none",
55
- onSuccess: c,
56
- onError: f,
57
- extraParams: l = {},
58
- createButtonText: u = "",
53
+ action: c,
54
+ behavior: s = "none",
55
+ onSuccess: f,
56
+ onError: l,
57
+ extraParams: u = {},
58
+ createButtonText: m = "",
59
59
  createMode: T = "register",
60
60
  dense: P = !1,
61
61
  slotProps: R = {},
62
- sx: h = {},
63
- mode: b = "normal",
64
- onClick: E = $
62
+ sx: b = {},
63
+ mode: h = "normal",
64
+ onClick: E = G,
65
+ isLatest: j = !1
65
66
  }) {
66
- const m = I(""), C = I(null), { t: p, loginPasskey: j, logoutPasskey: O, passkeyState: r } = K(), _ = v(async (s = "") => {
67
+ const p = I(""), C = I(null), { t: i, loginPasskey: O, logoutPasskey: _, passkeyState: o } = N(), A = v(async (a = "") => {
67
68
  try {
68
- r.verifying = !0, r.error = "", s || (r.verifyingStatus = "");
69
- const o = await j({
70
- ...l,
71
- action: a,
72
- credentialId: s
73
- }), t = B({ expireInDays: 7 });
74
- k.remove("connected_did", t), k.remove("connected_pk", t), k.remove("connected_wallet_os", t), r.verifying = !1, o?.sessionToken && (await c({ ...o, encrypted: !1 }, (A) => A), r.verifyingStatus = "succeed");
75
- } catch (o) {
76
- N.error("Failed to verify passkey", o);
77
- const t = W(o, p("verifyPasskeyFailed"), p);
78
- r.verifying = !1, r.error = t, r.verifyingStatus = "error", await O(), f(new Error(t));
69
+ o.verifying = !0, o.error = "", a || (o.verifyingStatus = "");
70
+ const r = await O({
71
+ ...u,
72
+ action: c,
73
+ credentialId: a
74
+ }), t = H({ expireInDays: 7 });
75
+ k.remove("connected_did", t), k.remove("connected_pk", t), k.remove("connected_wallet_os", t), o.verifying = !1, r?.sessionToken && (await f({ ...r, encrypted: !1 }, (F) => F), o.verifyingStatus = "succeed");
76
+ } catch (r) {
77
+ W.error("Failed to verify passkey", r);
78
+ const t = Y(r, i("verifyPasskeyFailed"), i);
79
+ o.verifying = !1, o.error = t, o.verifyingStatus = "error", await _(), l(new Error(t));
79
80
  }
80
81
  }), y = v(
81
- (s) => {
82
- if (!r.sent) return;
83
- s.preventDefault();
84
- const o = z(s.clipboardData.getData("text/plain").slice(0, w));
85
- if (!/^\d+$/.test(o)) return;
86
- r.code = o.padEnd(w, " ");
87
- const t = document.getElementById(`code-input-${o.length}`);
82
+ (a) => {
83
+ if (!o.sent) return;
84
+ a.preventDefault();
85
+ const r = z(a.clipboardData.getData("text/plain").slice(0, w));
86
+ if (!/^\d+$/.test(r)) return;
87
+ o.code = r.padEnd(w, " ");
88
+ const t = document.getElementById(`code-input-${r.length}`);
88
89
  t && t.focus();
89
90
  },
90
- [r]
91
+ [o]
91
92
  );
92
- F(() => (document.addEventListener("paste", y), () => {
93
+ L(() => (document.addEventListener("paste", y), () => {
93
94
  document.removeEventListener("paste", y);
94
95
  }), [y]);
95
96
  const g = v(() => {
96
- m.current === "verifying" ? _() : m.current === "creating" && C.current.open();
97
+ p.current === "verifying" ? A() : p.current === "creating" && C.current.open();
97
98
  });
98
99
  return M(d, () => ({
99
100
  click: g
100
- })), i === "none" ? null : /* @__PURE__ */ q(D, { children: [
101
- ["both", "only-existing"].includes(i) ? /* @__PURE__ */ n(
101
+ })), s === "none" ? null : /* @__PURE__ */ q(D, { children: [
102
+ ["both", "only-existing"].includes(s) ? /* @__PURE__ */ n(
102
103
  x,
103
104
  {
105
+ isLatest: j,
106
+ t: i,
104
107
  action: "verifying",
105
- state: r,
106
- title: p("usePasskey"),
108
+ state: o,
109
+ title: i("usePasskey"),
107
110
  onClick: () => {
108
- m.current = "verifying", g(), E();
111
+ p.current = "verifying", g(), E();
109
112
  },
110
113
  dense: P,
111
114
  slotProps: R,
112
- sx: h,
113
- mode: b,
114
- icon: /* @__PURE__ */ n(S, { icon: H, fontSize: "1em" })
115
+ sx: b,
116
+ mode: h,
117
+ icon: /* @__PURE__ */ n(S, { icon: V, fontSize: "1em" })
115
118
  }
116
119
  ) : null,
117
- ["both", "only-new"].includes(i) ? /* @__PURE__ */ q(D, { children: [
120
+ ["both", "only-new"].includes(s) ? /* @__PURE__ */ q(D, { children: [
118
121
  /* @__PURE__ */ n(
119
122
  x,
120
123
  {
124
+ t: i,
121
125
  action: "creating",
122
- state: r,
123
- title: u || p("createPasskey"),
126
+ state: o,
127
+ title: m || i("createPasskey"),
124
128
  onClick: () => {
125
- m.current = "creating", g(), E();
129
+ p.current = "creating", g(), E();
126
130
  },
127
131
  dense: P,
128
132
  slotProps: R,
129
- sx: h,
130
- mode: b,
131
- icon: /* @__PURE__ */ n(S, { icon: V, fontSize: "1em" })
133
+ sx: b,
134
+ mode: h,
135
+ icon: /* @__PURE__ */ n(S, { icon: $, fontSize: "1em" })
132
136
  }
133
137
  ),
134
138
  /* @__PURE__ */ n(
135
- J,
139
+ Q,
136
140
  {
137
141
  ref: C,
138
- action: a,
142
+ action: c,
139
143
  createMode: T,
140
- extraParams: l,
141
- onSuccess: c,
142
- onError: f
144
+ extraParams: u,
145
+ onSuccess: f,
146
+ onError: l
143
147
  }
144
148
  )
145
149
  ] }) : null
146
150
  ] });
147
151
  }
148
- Q.propTypes = {
152
+ U.propTypes = {
149
153
  action: e.string.isRequired,
150
154
  onSuccess: e.func.isRequired,
151
155
  onError: e.func.isRequired,
@@ -158,8 +162,9 @@ Q.propTypes = {
158
162
  sx: e.oneOfType([e.object, e.array]),
159
163
  mode: e.oneOf(["simple", "normal"]),
160
164
  onClick: e.func,
161
- ref: e.any
165
+ ref: e.any,
166
+ isLatest: e.bool
162
167
  };
163
168
  export {
164
- Q as default
169
+ U as default
165
170
  };
@@ -1,7 +1,7 @@
1
1
  import { jsxs as V, jsx as O } from "react/jsx-runtime";
2
2
  import p from "prop-types";
3
3
  import z from "lodash/isUndefined";
4
- import { createContext as J, use as K } from "react";
4
+ import { use as J, createContext as K } from "react";
5
5
  import u from "@arcblock/ux/lib/Toast";
6
6
  import { useReactive as g, useMemoizedFn as i, useCreation as W } from "ahooks";
7
7
  import w from "lodash/noop";
@@ -12,7 +12,7 @@ import { getBlockletData as H, getFederatedEnabled as X, getMaster as Q } from "
12
12
  import { startRegistration as Y, startAuthentication as Z } from "@simplewebauthn/browser";
13
13
  import { createAxios as $, getWebAuthnErrorMessage as h, logger as U, getApiErrorMessage as A } from "../utils.js";
14
14
  import { parseResponse as ee, PassportSwitcher as se } from "../components/PassportSwitcher.js";
15
- const F = J({}), { Provider: te, Consumer: he } = F, re = {
15
+ const F = K({}), { Provider: te, Consumer: he } = F, re = {
16
16
  zh: {
17
17
  cancel: "取消",
18
18
  usePasskey: "使用 Passkey",
@@ -260,7 +260,7 @@ function ae({
260
260
  );
261
261
  }
262
262
  function me() {
263
- return K(F);
263
+ return J(F);
264
264
  }
265
265
  ae.propTypes = {
266
266
  children: p.node.isRequired,
@@ -2,7 +2,7 @@ import { jsxs as l, jsx as o, Fragment as L } from "react/jsx-runtime";
2
2
  import c from "prop-types";
3
3
  import { useState as G, useImperativeHandle as N } from "react";
4
4
  import p from "@emotion/styled";
5
- import { Dialog as Y, DialogTitle as J, DialogContent as Q, DialogActions as U, Alert as X, TextField as j, Stack as Z, Box as z, Button as k, CircularProgress as A } from "@mui/material";
5
+ import { Alert as Y, TextField as j, Stack as J, Box as z, Dialog as Q, DialogTitle as U, DialogContent as X, Button as k, CircularProgress as A, DialogActions as Z } from "@mui/material";
6
6
  import m from "validator/lib/isEmail";
7
7
  import { Icon as ee } from "@iconify/react";
8
8
  import te from "@iconify-icons/material-symbols/passkey-rounded";
@@ -134,7 +134,7 @@ function ne({ ref: y, extraParams: C = {}, createMode: D = "connect", action: P,
134
134
  /* @__PURE__ */ l(le, { children: [
135
135
  /* @__PURE__ */ o(b, { variant: "body1", children: i("createPasskeyDesc1") }),
136
136
  /* @__PURE__ */ o(b, { variant: "body1", children: i("createPasskeyDesc2") }),
137
- e.error && /* @__PURE__ */ o(X, { severity: "error", children: e.error }),
137
+ e.error && /* @__PURE__ */ o(Y, { severity: "error", children: e.error }),
138
138
  a && /* @__PURE__ */ l(pe, { children: [
139
139
  !e.sent && /* @__PURE__ */ o(
140
140
  j,
@@ -155,7 +155,7 @@ function ne({ ref: y, extraParams: C = {}, createMode: D = "connect", action: P,
155
155
  }
156
156
  ),
157
157
  e.sent && !e.verified && /* @__PURE__ */ l(
158
- Z,
158
+ J,
159
159
  {
160
160
  direction: "column",
161
161
  sx: {
@@ -211,17 +211,17 @@ ne.propTypes = {
211
211
  onError: c.func,
212
212
  ref: c.any.isRequired
213
213
  };
214
- const ae = p(Y)`
214
+ const ae = p(Q)`
215
215
  .MuiDialog-paper {
216
216
  border-radius: 12px;
217
217
  max-width: 440px;
218
218
  }
219
- `, se = p(J)`
219
+ `, se = p(U)`
220
220
  text-align: center;
221
221
  padding: 24px 24px 16px;
222
222
  font-size: 20px;
223
223
  font-weight: 600;
224
- `, le = p(Q)`
224
+ `, le = p(X)`
225
225
  padding: 0 24px;
226
226
 
227
227
  .MuiTypography-body1 {
@@ -234,7 +234,7 @@ const ae = p(Y)`
234
234
  margin-top: 16px;
235
235
  width: 100%;
236
236
  }
237
- `, ce = p(U)`
237
+ `, ce = p(Z)`
238
238
  text-align: center;
239
239
  padding: 16px 24px 24px;
240
240