@arcblock/did-connect-react 3.5.2 → 4.0.0-beta.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/ConnectContext.d.ts +13 -0
- package/dist/ConnectContext.d.ts.map +1 -0
- package/dist/ConnectContext.js +14 -0
- package/dist/ConnectContext.js.map +1 -0
- package/dist/ConnectProvider.d.ts +11 -0
- package/dist/ConnectProvider.d.ts.map +1 -0
- package/dist/ConnectProvider.js +23 -0
- package/dist/ConnectProvider.js.map +1 -0
- package/dist/compat/SessionProvider.d.ts +22 -0
- package/dist/compat/SessionProvider.d.ts.map +1 -0
- package/dist/compat/SessionProvider.js +17 -0
- package/dist/compat/SessionProvider.js.map +1 -0
- package/dist/compat/index.d.ts +4 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +3 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/useSessionContext.d.ts +14 -0
- package/dist/compat/useSessionContext.d.ts.map +1 -0
- package/dist/compat/useSessionContext.js +20 -0
- package/dist/compat/useSessionContext.js.map +1 -0
- package/dist/components/LoginPage.d.ts +15 -0
- package/dist/components/LoginPage.d.ts.map +1 -0
- package/dist/components/LoginPage.js +33 -0
- package/dist/components/LoginPage.js.map +1 -0
- package/dist/components/UserAvatar.d.ts +19 -0
- package/dist/components/UserAvatar.d.ts.map +1 -0
- package/dist/components/UserAvatar.js +45 -0
- package/dist/components/UserAvatar.js.map +1 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useConnect.d.ts +15 -0
- package/dist/hooks/useConnect.d.ts.map +1 -0
- package/dist/hooks/useConnect.js +19 -0
- package/dist/hooks/useConnect.js.map +1 -0
- package/dist/hooks/useEmail.d.ts +11 -0
- package/dist/hooks/useEmail.d.ts.map +1 -0
- package/dist/hooks/useEmail.js +47 -0
- package/dist/hooks/useEmail.js.map +1 -0
- package/dist/hooks/useOAuth.d.ts +12 -0
- package/dist/hooks/useOAuth.d.ts.map +1 -0
- package/dist/hooks/useOAuth.js +75 -0
- package/dist/hooks/useOAuth.js.map +1 -0
- package/dist/hooks/usePasskey.d.ts +14 -0
- package/dist/hooks/usePasskey.d.ts.map +1 -0
- package/dist/hooks/usePasskey.js +35 -0
- package/dist/hooks/usePasskey.js.map +1 -0
- package/dist/hooks/useSession.d.ts +12 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +30 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/internals/blocklet-config.d.ts +22 -0
- package/dist/internals/blocklet-config.d.ts.map +1 -0
- package/dist/internals/blocklet-config.js +26 -0
- package/dist/internals/blocklet-config.js.map +1 -0
- package/dist/internals/local-storage-adapter.d.ts +12 -0
- package/dist/internals/local-storage-adapter.d.ts.map +1 -0
- package/dist/internals/local-storage-adapter.js +32 -0
- package/dist/internals/local-storage-adapter.js.map +1 -0
- package/dist/internals/use-sync-state.d.ts +18 -0
- package/dist/internals/use-sync-state.d.ts.map +1 -0
- package/dist/internals/use-sync-state.js +38 -0
- package/dist/internals/use-sync-state.js.map +1 -0
- package/package.json +33 -79
- package/LICENSE +0 -13
- package/README.md +0 -134
- package/dist/standalone/did-connect-react.css +0 -1
- package/dist/standalone/index.js +0 -136774
- package/lib/Address/index.js +0 -4
- package/lib/Avatar/index.js +0 -4
- package/lib/Button/index.js +0 -17
- package/lib/Connect/assets/locale.js +0 -147
- package/lib/Connect/assets/login-bg.png +0 -0
- package/lib/Connect/assets/login-slogan.js +0 -9
- package/lib/Connect/components/action-button.js +0 -26
- package/lib/Connect/components/app-tips.js +0 -132
- package/lib/Connect/components/auto-height.js +0 -31
- package/lib/Connect/components/back-button.js +0 -25
- package/lib/Connect/components/connect-status.js +0 -263
- package/lib/Connect/components/did-connect-title.js +0 -127
- package/lib/Connect/components/download-tips.js +0 -52
- package/lib/Connect/components/loading.js +0 -26
- package/lib/Connect/components/login-item/connect-choose-list.js +0 -257
- package/lib/Connect/components/login-item/connect-provider-list.js +0 -345
- package/lib/Connect/components/login-item/login-method-item.js +0 -147
- package/lib/Connect/components/login-item/mobile-login-item.js +0 -116
- package/lib/Connect/components/login-item/passkey-login-item.js +0 -44
- package/lib/Connect/components/login-item/wallet-login-options.js +0 -114
- package/lib/Connect/components/login-item/web-login-item.js +0 -104
- package/lib/Connect/components/mask-overlay.js +0 -34
- package/lib/Connect/components/refresh-overlay.js +0 -57
- package/lib/Connect/components/switch-app.js +0 -70
- package/lib/Connect/connect.js +0 -505
- package/lib/Connect/contexts/state.js +0 -156
- package/lib/Connect/fallback-connect.js +0 -53
- package/lib/Connect/fullpage.js +0 -5
- package/lib/Connect/hooks/auth-url.js +0 -23
- package/lib/Connect/hooks/method-list.js +0 -46
- package/lib/Connect/hooks/page-show.js +0 -17
- package/lib/Connect/hooks/provider-list.js +0 -69
- package/lib/Connect/hooks/security.js +0 -27
- package/lib/Connect/hooks/token.js +0 -296
- package/lib/Connect/hooks/use-apps.js +0 -19
- package/lib/Connect/hooks/use-quick-connect.js +0 -86
- package/lib/Connect/index.js +0 -16
- package/lib/Connect/landing-page.js +0 -5
- package/lib/Connect/plugins/email/index.js +0 -65
- package/lib/Connect/plugins/email/list-item.js +0 -31
- package/lib/Connect/plugins/email/placeholder.js +0 -284
- package/lib/Connect/plugins/index.js +0 -4
- package/lib/Connect/use-connect.js +0 -164
- package/lib/Connect/with-blocklet.js +0 -15
- package/lib/Connect/with-bridge-call.js +0 -108
- package/lib/Federated/context.js +0 -61
- package/lib/Federated/index.js +0 -7
- package/lib/Logo/index.js +0 -4
- package/lib/OAuth/bind-conflict-alert.js +0 -29
- package/lib/OAuth/context.js +0 -277
- package/lib/OAuth/guest.svg.js +0 -5
- package/lib/OAuth/index.js +0 -7
- package/lib/OAuth/passport-switcher.js +0 -5
- package/lib/Passkey/actions.js +0 -170
- package/lib/Passkey/constants.js +0 -4
- package/lib/Passkey/context.js +0 -281
- package/lib/Passkey/dialog.js +0 -280
- package/lib/Passkey/icon.js +0 -13
- package/lib/Passkey/index.js +0 -9
- package/lib/Service/index.js +0 -62
- package/lib/Session/assets/did-spaces-guide-cover.svg.js +0 -111
- package/lib/Session/assets/did-spaces-guide-icon.svg.js +0 -9
- package/lib/Session/context.js +0 -5
- package/lib/Session/did-spaces-guide.js +0 -136
- package/lib/Session/handler.js +0 -55
- package/lib/Session/hooks/use-federated.js +0 -64
- package/lib/Session/hooks/use-mobile.js +0 -8
- package/lib/Session/hooks/use-protected-routes.js +0 -11
- package/lib/Session/hooks/use-session-token.js +0 -181
- package/lib/Session/hooks/use-verify.js +0 -45
- package/lib/Session/index.js +0 -941
- package/lib/Session/libs/constants.js +0 -18
- package/lib/Session/libs/did-spaces.js +0 -10
- package/lib/Session/libs/federated.js +0 -42
- package/lib/Session/libs/index.js +0 -15
- package/lib/Session/libs/locales.js +0 -161
- package/lib/Session/libs/login-mobile.js +0 -55
- package/lib/Session/window-focus-aware.js +0 -17
- package/lib/SessionManager/index.js +0 -4
- package/lib/Storage/engine/cookie.js +0 -22
- package/lib/Storage/engine/local-storage.js +0 -37
- package/lib/Storage/index.js +0 -23
- package/lib/User/index.js +0 -6
- package/lib/User/use-did.js +0 -59
- package/lib/User/wrap-did.js +0 -13
- package/lib/WebWalletSWKeeper/index.js +0 -5
- package/lib/components/PassportSwitcher.js +0 -128
- package/lib/constant.js +0 -23
- package/lib/error.js +0 -8
- package/lib/hooks/use-locale.js +0 -7
- package/lib/index.js +0 -111
- package/lib/locales/en.js +0 -17
- package/lib/locales/index.js +0 -10
- package/lib/locales/zh.js +0 -17
- package/lib/node_modules/@blocklet/js-sdk/dist/index.js +0 -512
- package/lib/packages/did-connect/package.json.js +0 -7
- package/lib/types.d.ts +0 -355
- package/lib/utils.js +0 -225
package/lib/Passkey/context.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { jsxs as z, jsx as O } from "react/jsx-runtime";
|
|
2
|
-
import y from "prop-types";
|
|
3
|
-
import J from "lodash/isUndefined";
|
|
4
|
-
import { use as K, createContext as W } from "react";
|
|
5
|
-
import u from "@arcblock/ux/lib/Toast";
|
|
6
|
-
import { useReactive as g, useMemoizedFn as i, useCreation as q } from "ahooks";
|
|
7
|
-
import w from "lodash/noop";
|
|
8
|
-
import { joinURL as S } from "ufo";
|
|
9
|
-
import { translate as G } from "@arcblock/ux/lib/Locale/util";
|
|
10
|
-
import { BLOCKLET_SERVICE_PATH_PREFIX as H } from "@arcblock/ux/lib/Util/constant";
|
|
11
|
-
import { getBlockletData as X, getFederatedEnabled as $, getMaster as Q } from "@arcblock/ux/lib/Util/federated";
|
|
12
|
-
import { startRegistration as Y, startAuthentication as Z } from "@simplewebauthn/browser";
|
|
13
|
-
import { createAxios as ee, getWebAuthnErrorMessage as h, logger as U, getApiErrorMessage as A } from "../utils.js";
|
|
14
|
-
import { parseResponse as se, PassportSwitcher as te } from "../components/PassportSwitcher.js";
|
|
15
|
-
import F from "../Connect/assets/locale.js";
|
|
16
|
-
const E = W({}), { Provider: re, Consumer: ve } = E, ae = {
|
|
17
|
-
zh: {
|
|
18
|
-
...F.zh,
|
|
19
|
-
cancel: "取消",
|
|
20
|
-
usePasskey: "使用 Passkey",
|
|
21
|
-
createPasskey: "新建 Passkey",
|
|
22
|
-
creatingPasskey: "创建 Passkey...",
|
|
23
|
-
connectPasskey: "绑定 Passkey",
|
|
24
|
-
nonePasskey: "未配置 Passkey 方式",
|
|
25
|
-
connectPasskeySucceed: "Passkey 绑定成功",
|
|
26
|
-
disconnectPasskeySucceed: "Passkey 解绑成功",
|
|
27
|
-
verifyPasskeyFailed: "Passkey 验证失败",
|
|
28
|
-
connectPasskeyFailed: "Passkey 绑定失败",
|
|
29
|
-
disconnectPasskeyFailed: "Passkey 解绑失败",
|
|
30
|
-
createPasskeyDesc1: "Passkey 是一种密码替代品,使用指纹、面部识别、设备密码或 PIN 验证您的身份。",
|
|
31
|
-
createPasskeyDesc2: "Passkey 可以用于登录、验证,作为您账户简单且安全的替代方案。",
|
|
32
|
-
emailPlaceholder: "请输入邮箱以作为备用",
|
|
33
|
-
verifyButton: "验证邮箱",
|
|
34
|
-
sendCodeButton: "获取验证码",
|
|
35
|
-
codeSentMessage: "我们已向 {email} 发送验证码,验证码将在 30 分钟内有效,请检查您的邮箱或垃圾邮件文件夹。",
|
|
36
|
-
codeSentSuccess: "验证码发送成功",
|
|
37
|
-
noPassports: "没有可更换的通行证",
|
|
38
|
-
cancelAuth: "取消授权",
|
|
39
|
-
emailInvalid: "邮箱格式不正确",
|
|
40
|
-
webauthn: {
|
|
41
|
-
error: {
|
|
42
|
-
canceled: "身份验证已被取消",
|
|
43
|
-
security: "身份验证过程中出现安全错误",
|
|
44
|
-
notSupported: "当前浏览器不支持 Passkey 身份验证",
|
|
45
|
-
aborted: "身份验证已被中止"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
en: {
|
|
50
|
-
...F.en,
|
|
51
|
-
cancel: "Cancel",
|
|
52
|
-
usePasskey: "Use Existing Passkey",
|
|
53
|
-
createPasskey: "Create New Passkey",
|
|
54
|
-
creatingPasskey: "Creating Passkey...",
|
|
55
|
-
connectPasskey: "Connect Passkey",
|
|
56
|
-
nonePasskey: "Passkey is not configured",
|
|
57
|
-
connectPasskeySucceed: "Passkey add succeed",
|
|
58
|
-
disconnectPasskeySucceed: "Passkey remove succeed",
|
|
59
|
-
verifyPasskeyFailed: "Passkey verify failed",
|
|
60
|
-
connectPasskeyFailed: "Passkey add failed",
|
|
61
|
-
disconnectPasskeyFailed: "Passkey remove failed",
|
|
62
|
-
createPasskeyDesc1: "Passkeys are a password replacement that validates your identity using touch, facial recognition, a device password, or a PIN.",
|
|
63
|
-
createPasskeyDesc2: "Passkeys can be used for sign-in, verification as a simple and secure alternative to your account.",
|
|
64
|
-
emailPlaceholder: "Enter your email address",
|
|
65
|
-
verifyButton: "Verify Email",
|
|
66
|
-
sendCodeButton: "Get Verify Code",
|
|
67
|
-
codeSentMessage: "We just sent a verification code to {email}, the code will be valid for 30 minutes, please check your inbox or spam folder.",
|
|
68
|
-
codeSentSuccess: "Verification code sent successfully",
|
|
69
|
-
noPassports: "No passports to switch",
|
|
70
|
-
cancelAuth: "Cancel authentication",
|
|
71
|
-
emailInvalid: "Invalid email address",
|
|
72
|
-
webauthn: {
|
|
73
|
-
error: {
|
|
74
|
-
canceled: "Authentication was canceled",
|
|
75
|
-
security: "A security error occurred during authentication",
|
|
76
|
-
notSupported: "This browser does not support passkey authentication",
|
|
77
|
-
aborted: "Authentication was aborted"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
function ne({
|
|
83
|
-
children: m,
|
|
84
|
-
locale: l = "en",
|
|
85
|
-
onAddPasskey: C = w,
|
|
86
|
-
onRemovePasskey: I = w,
|
|
87
|
-
onSwitchPassport: R = w,
|
|
88
|
-
session: x = null
|
|
89
|
-
}) {
|
|
90
|
-
const v = S(window.env?.apiPrefix || H, "/api/passkey"), r = g({
|
|
91
|
-
baseUrl: "/",
|
|
92
|
-
session: void 0,
|
|
93
|
-
connecting: !1,
|
|
94
|
-
disconnecting: !1,
|
|
95
|
-
targetAppPid: void 0
|
|
96
|
-
}), o = g({
|
|
97
|
-
open: !1,
|
|
98
|
-
currentUser: null,
|
|
99
|
-
passports: [],
|
|
100
|
-
selectedPassport: void 0,
|
|
101
|
-
reset() {
|
|
102
|
-
o.open = !1, o.currentUser = null, o.passports = [], o.selectedPassport = void 0;
|
|
103
|
-
}
|
|
104
|
-
}), d = g({
|
|
105
|
-
user: null,
|
|
106
|
-
loading: !1,
|
|
107
|
-
creating: !1,
|
|
108
|
-
verifying: !1,
|
|
109
|
-
creatingStatus: "",
|
|
110
|
-
verifyingStatus: "",
|
|
111
|
-
error: "",
|
|
112
|
-
email: "",
|
|
113
|
-
code: "",
|
|
114
|
-
verified: !window?.blocklet?.settings?.kyc?.email,
|
|
115
|
-
sent: !1,
|
|
116
|
-
openDialog: !1,
|
|
117
|
-
get status() {
|
|
118
|
-
return this.creating || this.verifying ? "scanned" : this.creatingStatus === "succeed" || this.verifyingStatus === "succeed" ? "succeed" : this.creatingStatus === "error" || this.verifyingStatus === "error" ? "error" : "";
|
|
119
|
-
},
|
|
120
|
-
reset() {
|
|
121
|
-
d.creating = !1, d.verifying = !1, d.creatingStatus = "", d.verifyingStatus = "", d.error = "";
|
|
122
|
-
}
|
|
123
|
-
}), n = i((t, e = {}) => G(ae, t, l, "en", e)), c = q(() => ee({ baseURL: S(r.baseUrl, v), sessionTokenKey: "__sst", timeout: 60 * 1e3 }), [r.baseUrl, v]), B = i(async () => {
|
|
124
|
-
if (r.baseUrl === "/")
|
|
125
|
-
return window.blocklet;
|
|
126
|
-
try {
|
|
127
|
-
if (new URL(r.baseUrl).host === window.location.host)
|
|
128
|
-
return window.blocklet;
|
|
129
|
-
} catch {
|
|
130
|
-
}
|
|
131
|
-
return await X(r.baseUrl);
|
|
132
|
-
}), P = window?.blocklet?.componentId, T = (t) => {
|
|
133
|
-
r.baseUrl = t || "/";
|
|
134
|
-
}, M = (t) => {
|
|
135
|
-
r.targetAppPid = t;
|
|
136
|
-
}, b = i(async (t) => {
|
|
137
|
-
const { data: e } = await c.get("/register", { params: t });
|
|
138
|
-
console.warn("passkey.create.options", e);
|
|
139
|
-
try {
|
|
140
|
-
const s = await Y({ optionsJSON: e, useAutoRegister: !1 });
|
|
141
|
-
console.warn("passkey.create.response", s);
|
|
142
|
-
const { data: a } = await c.post("/register", s, { params: { challenge: e.challenge } });
|
|
143
|
-
if (console.warn("passkey.create.result", a), !a.verified)
|
|
144
|
-
throw new Error(n("createPasskeyFailed"));
|
|
145
|
-
return a;
|
|
146
|
-
} catch (s) {
|
|
147
|
-
throw console.error("passkey.create.error", s), s.name ? new Error(h(s, n("createPasskeyFailed"), n)) : s;
|
|
148
|
-
}
|
|
149
|
-
}), k = i(async (t) => {
|
|
150
|
-
const { data: e } = await c.get("/auth", { params: t });
|
|
151
|
-
console.warn("passkey.auth.options", e);
|
|
152
|
-
try {
|
|
153
|
-
const s = await Z({ optionsJSON: e });
|
|
154
|
-
console.warn("passkey.auth.response", s);
|
|
155
|
-
const { data: a } = await c.post("/auth", s, {
|
|
156
|
-
params: { challenge: e.challenge, targetAppPid: r.targetAppPid }
|
|
157
|
-
});
|
|
158
|
-
if (console.warn("passkey.auth.result", a), !a.verified)
|
|
159
|
-
throw new Error(n("verifyPasskeyFailed"));
|
|
160
|
-
return a;
|
|
161
|
-
} catch (s) {
|
|
162
|
-
throw console.error("passkey.auth.error", s), s.name ? new Error(h(s, n("verifyPasskeyFailed"), n)) : s;
|
|
163
|
-
}
|
|
164
|
-
}), D = async (t) => {
|
|
165
|
-
r.connecting = !0;
|
|
166
|
-
try {
|
|
167
|
-
const e = await b({
|
|
168
|
-
...t,
|
|
169
|
-
locale: l,
|
|
170
|
-
componentId: P
|
|
171
|
-
});
|
|
172
|
-
return u.success(n("connectPasskeySucceed")), C(e), e;
|
|
173
|
-
} catch (e) {
|
|
174
|
-
U.error("Failed to connect passkey", e), u.error(A(e, n("connectPasskeyFailed")));
|
|
175
|
-
} finally {
|
|
176
|
-
r.connecting = !1;
|
|
177
|
-
}
|
|
178
|
-
}, N = async ({ session: t, connectedAccount: e }) => {
|
|
179
|
-
r.session = t, r.disconnecting = !0;
|
|
180
|
-
try {
|
|
181
|
-
const s = await k({
|
|
182
|
-
action: "disconnect",
|
|
183
|
-
locale: l,
|
|
184
|
-
componentId: P,
|
|
185
|
-
sourceAppPid: t?.user?.sourceAppPid,
|
|
186
|
-
credentialId: e.id
|
|
187
|
-
});
|
|
188
|
-
u.success(n("disconnectPasskeySucceed")), I(s);
|
|
189
|
-
} catch (s) {
|
|
190
|
-
U.error("Failed to disconnect passkey", s), u.error(A(s, n("disconnectPasskeyFailed")));
|
|
191
|
-
} finally {
|
|
192
|
-
r.disconnecting = !1;
|
|
193
|
-
}
|
|
194
|
-
}, j = async (t = {}) => {
|
|
195
|
-
try {
|
|
196
|
-
const { data: e } = await c.get("/passports");
|
|
197
|
-
e.length ? (o.open = !0, o.currentUser = t, o.passports = e || []) : u.error(n("noPassports"));
|
|
198
|
-
} catch (e) {
|
|
199
|
-
u.error(e.message || n("getPassportFailed"));
|
|
200
|
-
}
|
|
201
|
-
}, L = i((...t) => {
|
|
202
|
-
o.reset(), R(...t);
|
|
203
|
-
}), _ = i(async ({ action: t = "login", ...e } = {}) => {
|
|
204
|
-
const s = r.baseUrl;
|
|
205
|
-
if (e?.sourceAppPid === window.blocklet?.appPid)
|
|
206
|
-
r.baseUrl = window.blocklet?.appUrl || "/";
|
|
207
|
-
else if (e?.sourceAppPid) {
|
|
208
|
-
const a = await B(), p = $(a), f = Q(a);
|
|
209
|
-
p && f?.appPid && e?.sourceAppPid === f?.appPid && (r.baseUrl = f.appUrl);
|
|
210
|
-
}
|
|
211
|
-
try {
|
|
212
|
-
const a = {
|
|
213
|
-
...e,
|
|
214
|
-
action: t,
|
|
215
|
-
locale: l,
|
|
216
|
-
componentId: P
|
|
217
|
-
};
|
|
218
|
-
J(a.inviter) && window.localStorage.getItem("inviter") && (a.inviter = window.localStorage.getItem("inviter"));
|
|
219
|
-
const p = se(await k(a));
|
|
220
|
-
return p.provider = "passkey", p;
|
|
221
|
-
} catch (a) {
|
|
222
|
-
console.error("passkey.login.error", a);
|
|
223
|
-
const p = h(a, n("verifyPasskeyFailed"), n);
|
|
224
|
-
throw r.baseUrl = s, new Error(p);
|
|
225
|
-
}
|
|
226
|
-
}), V = i(() => {
|
|
227
|
-
});
|
|
228
|
-
return /* @__PURE__ */ z(
|
|
229
|
-
re,
|
|
230
|
-
{
|
|
231
|
-
value: {
|
|
232
|
-
api: c,
|
|
233
|
-
locale: l,
|
|
234
|
-
connectPasskey: D,
|
|
235
|
-
disconnectPasskey: N,
|
|
236
|
-
createPasskey: b,
|
|
237
|
-
verifyPasskey: k,
|
|
238
|
-
loginPasskey: _,
|
|
239
|
-
logoutPasskey: V,
|
|
240
|
-
switchPassport: j,
|
|
241
|
-
baseUrl: r.baseUrl,
|
|
242
|
-
setBaseUrl: T,
|
|
243
|
-
setTargetAppPid: M,
|
|
244
|
-
passkeyState: d,
|
|
245
|
-
disconnecting: r.disconnecting,
|
|
246
|
-
connecting: r.connecting,
|
|
247
|
-
t: n
|
|
248
|
-
},
|
|
249
|
-
children: [
|
|
250
|
-
m,
|
|
251
|
-
/* @__PURE__ */ O(
|
|
252
|
-
te,
|
|
253
|
-
{
|
|
254
|
-
api: c,
|
|
255
|
-
locale: l,
|
|
256
|
-
switchState: o,
|
|
257
|
-
onSwitchPassport: L,
|
|
258
|
-
session: x
|
|
259
|
-
}
|
|
260
|
-
)
|
|
261
|
-
]
|
|
262
|
-
}
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
function be() {
|
|
266
|
-
return K(E);
|
|
267
|
-
}
|
|
268
|
-
ne.propTypes = {
|
|
269
|
-
children: y.node.isRequired,
|
|
270
|
-
locale: y.string,
|
|
271
|
-
onAddPasskey: y.func,
|
|
272
|
-
onRemovePasskey: y.func,
|
|
273
|
-
onSwitchPassport: y.func,
|
|
274
|
-
session: y.object
|
|
275
|
-
};
|
|
276
|
-
export {
|
|
277
|
-
ve as PasskeyConsumer,
|
|
278
|
-
E as PasskeyContext,
|
|
279
|
-
ne as PasskeyProvider,
|
|
280
|
-
be as usePasskey
|
|
281
|
-
};
|
package/lib/Passkey/dialog.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { jsxs as l, jsx as o, Fragment as L } from "react/jsx-runtime";
|
|
2
|
-
import c from "prop-types";
|
|
3
|
-
import { useState as G, useImperativeHandle as N } from "react";
|
|
4
|
-
import p from "@emotion/styled";
|
|
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
|
-
import m from "validator/lib/isEmail";
|
|
7
|
-
import { Icon as ee } from "@iconify/react";
|
|
8
|
-
import te from "@iconify-icons/material-symbols/passkey-rounded";
|
|
9
|
-
import { useMemoizedFn as d } from "ahooks";
|
|
10
|
-
import S from "@arcblock/ux/lib/Toast";
|
|
11
|
-
import b from "@arcblock/ux/lib/Typography";
|
|
12
|
-
import { getCookieOptions as re } from "@arcblock/ux/lib/Util";
|
|
13
|
-
import g from "lodash/trim";
|
|
14
|
-
import ie from "base64-url";
|
|
15
|
-
import w from "js-cookie";
|
|
16
|
-
import $ from "lodash/noop";
|
|
17
|
-
import { usePasskey as oe } from "./context.js";
|
|
18
|
-
import { getWebAuthnErrorMessage as _ } from "../utils.js";
|
|
19
|
-
import { VERIFY_CODE_LENGTH as q } from "./constants.js";
|
|
20
|
-
function ne({ ref: y, extraParams: C = {}, createMode: D = "connect", action: P, onSuccess: I = $, onError: R = $ }) {
|
|
21
|
-
const { api: E, locale: T, t: i, loginPasskey: V, logoutPasskey: O, passkeyState: e, connectPasskey: W } = oe(), a = D === "register", [F, s] = G(!1), h = window.innerWidth < 600, B = d(() => {
|
|
22
|
-
e.openDialog = !0, e.error = "", e.creatingStatus = "", e.verifyingStatus = "";
|
|
23
|
-
const t = e.email;
|
|
24
|
-
s(t && a ? !m(t) : !1);
|
|
25
|
-
}), u = d(() => {
|
|
26
|
-
e.openDialog = !1, e.error = "", e.creatingStatus = "", e.verifyingStatus = "";
|
|
27
|
-
const t = e.email;
|
|
28
|
-
s(t && a ? !m(t) : !1);
|
|
29
|
-
}), H = d(async (t) => {
|
|
30
|
-
if (t.preventDefault(), a && !m(e.email)) {
|
|
31
|
-
s(!0);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
s(!1), e.loading = !0;
|
|
35
|
-
try {
|
|
36
|
-
await E.post(`../kyc/email/send?locale=${T}`, { email: e.email }), e.sent = !0, S.success(i("codeSentSuccess"));
|
|
37
|
-
} catch (r) {
|
|
38
|
-
S.error(r.message), document.getElementById("email-input")?.focus();
|
|
39
|
-
} finally {
|
|
40
|
-
e.loading = !1;
|
|
41
|
-
}
|
|
42
|
-
}), K = d(async (t = "") => {
|
|
43
|
-
try {
|
|
44
|
-
e.verifying = !0, e.error = "", t || (e.verifyingStatus = "");
|
|
45
|
-
const r = await V({
|
|
46
|
-
...C,
|
|
47
|
-
action: P,
|
|
48
|
-
credentialId: t
|
|
49
|
-
}), n = re({ expireInDays: 7 });
|
|
50
|
-
w.remove("connected_did", n), w.remove("connected_pk", n), w.remove("connected_wallet_os", n), e.verifying = !1, r?.sessionToken && (e.verifyingStatus = "succeed", I({ ...r, encrypted: !1 }, (f) => f));
|
|
51
|
-
} catch (r) {
|
|
52
|
-
console.error("Failed to verify passkey", r);
|
|
53
|
-
const n = _(r, i("verifyPasskeyFailed"));
|
|
54
|
-
e.verifying = !1, e.error = n, e.verifyingStatus = "error", await O(), R(new Error(n));
|
|
55
|
-
}
|
|
56
|
-
}), x = d(async () => {
|
|
57
|
-
if (a && !m(e.email)) {
|
|
58
|
-
s(!0);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
s(!1), e.creating = !0, e.error = "", e.creatingStatus = "";
|
|
62
|
-
try {
|
|
63
|
-
const t = await W({
|
|
64
|
-
...C,
|
|
65
|
-
action: P,
|
|
66
|
-
purpose: a ? "register" : "connect",
|
|
67
|
-
email: a ? ie.encode(e.email) : ""
|
|
68
|
-
});
|
|
69
|
-
if (!t) {
|
|
70
|
-
e.error = i("cancelAuth"), e.creatingStatus = "error", e.creating = !1, e.verifying = !1, e.verifyingStatus = "";
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
e.creating = !1, e.openDialog = !1, e.creatingStatus = "succeed", D === "connect" ? I({ ...t, encrypted: !1 }, (r) => r) : t?.credentialId && K(t.credentialId);
|
|
74
|
-
} catch (t) {
|
|
75
|
-
console.error("Failed to create passkey", t), e.creating = !1, e.error = _(t, i("createPasskeyFailed")), e.creatingStatus = "error";
|
|
76
|
-
}
|
|
77
|
-
}), v = d(async (t) => {
|
|
78
|
-
t && t.preventDefault(), e.loading = !0;
|
|
79
|
-
try {
|
|
80
|
-
await E.post(`../kyc/email/verify?locale=${T}`, { code: e.code }), e.verified = !0, x();
|
|
81
|
-
} catch (r) {
|
|
82
|
-
S.error(r.message), e.verified = !1, document.getElementById(`code-input-${g(e.code).length - 1}`)?.focus();
|
|
83
|
-
} finally {
|
|
84
|
-
e.loading = !1;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
N(y, () => ({
|
|
88
|
-
open: B,
|
|
89
|
-
close: u,
|
|
90
|
-
handleVerifyCode: v
|
|
91
|
-
}), [B, u, v]);
|
|
92
|
-
const M = () => /* @__PURE__ */ l(L, { children: [
|
|
93
|
-
/* @__PURE__ */ o(k, { onClick: u, sx: { color: "text.secondary" }, children: i("cancel") }),
|
|
94
|
-
a && /* @__PURE__ */ l(
|
|
95
|
-
k,
|
|
96
|
-
{
|
|
97
|
-
variant: "contained",
|
|
98
|
-
onClick: (
|
|
99
|
-
// eslint-disable-next-line no-nested-ternary
|
|
100
|
-
e.verified ? x : e.sent ? v : H
|
|
101
|
-
),
|
|
102
|
-
disabled: e.verifying || e.creating || !e.email || e.sent && g(e.code).length !== q,
|
|
103
|
-
children: [
|
|
104
|
-
(e.loading || e.creating) && /* @__PURE__ */ o(A, { size: 16, sx: { mr: 1 } }),
|
|
105
|
-
e.verified ? i("createPasskey") : e.sent ? i("verifyButton") : i("sendCodeButton")
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
),
|
|
109
|
-
!a && /* @__PURE__ */ o(
|
|
110
|
-
k,
|
|
111
|
-
{
|
|
112
|
-
variant: "contained",
|
|
113
|
-
color: "primary",
|
|
114
|
-
onClick: x,
|
|
115
|
-
disabled: e.loading || e.creating || a && (!e.email || !e.verified),
|
|
116
|
-
startIcon: (e.loading || e.creating) && /* @__PURE__ */ o(A, { size: 16, sx: { mr: 1 }, color: "inherit" }),
|
|
117
|
-
children: e.loading || e.creating ? i("creatingPasskey") : i("createPasskey")
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
] });
|
|
121
|
-
return /* @__PURE__ */ l(
|
|
122
|
-
ae,
|
|
123
|
-
{
|
|
124
|
-
open: e.openDialog,
|
|
125
|
-
onClose: u,
|
|
126
|
-
fullWidth: !0,
|
|
127
|
-
maxWidth: "sm",
|
|
128
|
-
fullScreen: h,
|
|
129
|
-
children: [
|
|
130
|
-
/* @__PURE__ */ l(se, { children: [
|
|
131
|
-
/* @__PURE__ */ o(de, { children: /* @__PURE__ */ o(ee, { icon: te, fontSize: 24, color: "initial" }) }),
|
|
132
|
-
i("createPasskey")
|
|
133
|
-
] }),
|
|
134
|
-
/* @__PURE__ */ l(le, { children: [
|
|
135
|
-
/* @__PURE__ */ o(b, { variant: "body1", children: i("createPasskeyDesc1") }),
|
|
136
|
-
/* @__PURE__ */ o(b, { variant: "body1", children: i("createPasskeyDesc2") }),
|
|
137
|
-
e.error && /* @__PURE__ */ o(Y, { severity: "error", children: e.error }),
|
|
138
|
-
a && /* @__PURE__ */ l(pe, { children: [
|
|
139
|
-
!e.sent && /* @__PURE__ */ o(
|
|
140
|
-
j,
|
|
141
|
-
{
|
|
142
|
-
type: "email",
|
|
143
|
-
id: "email-input",
|
|
144
|
-
size: "medium",
|
|
145
|
-
placeholder: i("emailPlaceholder"),
|
|
146
|
-
sx: { width: "100%", ".MuiFormHelperText-root": { ml: 0 } },
|
|
147
|
-
value: e.email,
|
|
148
|
-
onChange: (t) => {
|
|
149
|
-
e.email = t.target.value, s(!m(e.email));
|
|
150
|
-
},
|
|
151
|
-
disabled: e.loading || e.creating,
|
|
152
|
-
required: !0,
|
|
153
|
-
error: F,
|
|
154
|
-
helperText: F ? i("emailInvalid") : ""
|
|
155
|
-
}
|
|
156
|
-
),
|
|
157
|
-
e.sent && !e.verified && /* @__PURE__ */ l(
|
|
158
|
-
J,
|
|
159
|
-
{
|
|
160
|
-
direction: "column",
|
|
161
|
-
sx: {
|
|
162
|
-
justifyContent: "center",
|
|
163
|
-
alignItems: "center",
|
|
164
|
-
mb: 2
|
|
165
|
-
},
|
|
166
|
-
children: [
|
|
167
|
-
/* @__PURE__ */ o(b, { variant: "body2", children: i("codeSentMessage", { email: e.email }) }),
|
|
168
|
-
/* @__PURE__ */ o(z, { sx: { width: "100%", display: "flex", justifyContent: "space-between", gap: 2, mt: 0 }, children: Array(q).fill("").map((t, r) => /* @__PURE__ */ o(
|
|
169
|
-
j,
|
|
170
|
-
{
|
|
171
|
-
value: g(e.code[r]) || "",
|
|
172
|
-
type: "number",
|
|
173
|
-
margin: "none",
|
|
174
|
-
onChange: (n) => {
|
|
175
|
-
const f = e.code.split("");
|
|
176
|
-
f[r] = n.target.value, e.code = f.join(""), n.target.value && r < 5 && document.getElementById(`code-input-${r + 1}`)?.focus();
|
|
177
|
-
},
|
|
178
|
-
onKeyDown: (n) => {
|
|
179
|
-
n.key === "Backspace" && !g(e.code[r]) && r > 0 && document.getElementById(`code-input-${r - 1}`)?.focus();
|
|
180
|
-
},
|
|
181
|
-
disabled: e.loading,
|
|
182
|
-
required: !0,
|
|
183
|
-
id: `code-input-${r}`,
|
|
184
|
-
autoComplete: "off",
|
|
185
|
-
slotProps: {
|
|
186
|
-
htmlInput: {
|
|
187
|
-
maxLength: 1,
|
|
188
|
-
style: { textAlign: "center", fontSize: "1.5rem" },
|
|
189
|
-
autoComplete: "off"
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
`code-input-${r}`
|
|
194
|
-
)) })
|
|
195
|
-
]
|
|
196
|
-
}
|
|
197
|
-
)
|
|
198
|
-
] }),
|
|
199
|
-
h && /* @__PURE__ */ o(z, { sx: { display: "flex", justifyContent: "flex-end", alignItems: "center", mt: 2 }, children: M() })
|
|
200
|
-
] }),
|
|
201
|
-
!h && /* @__PURE__ */ o(ce, { children: M() })
|
|
202
|
-
]
|
|
203
|
-
}
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
ne.propTypes = {
|
|
207
|
-
extraParams: c.object,
|
|
208
|
-
createMode: c.string,
|
|
209
|
-
action: c.string.isRequired,
|
|
210
|
-
onSuccess: c.func,
|
|
211
|
-
onError: c.func,
|
|
212
|
-
ref: c.any.isRequired
|
|
213
|
-
};
|
|
214
|
-
const ae = p(Q)`
|
|
215
|
-
.MuiDialog-paper {
|
|
216
|
-
border-radius: 12px;
|
|
217
|
-
max-width: 440px;
|
|
218
|
-
}
|
|
219
|
-
`, se = p(U)`
|
|
220
|
-
text-align: center;
|
|
221
|
-
padding: 24px 24px 16px;
|
|
222
|
-
font-size: 20px;
|
|
223
|
-
font-weight: 600;
|
|
224
|
-
`, le = p(X)`
|
|
225
|
-
padding: 0 24px;
|
|
226
|
-
|
|
227
|
-
.MuiTypography-body1 {
|
|
228
|
-
font-size: 14px;
|
|
229
|
-
line-height: 1.5;
|
|
230
|
-
margin-bottom: 16px;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
.MuiTextField-root {
|
|
234
|
-
margin-top: 16px;
|
|
235
|
-
width: 100%;
|
|
236
|
-
}
|
|
237
|
-
`, ce = p(Z)`
|
|
238
|
-
text-align: center;
|
|
239
|
-
padding: 16px 24px 24px;
|
|
240
|
-
|
|
241
|
-
.MuiButton-root {
|
|
242
|
-
text-transform: none;
|
|
243
|
-
font-size: 14px;
|
|
244
|
-
border-radius: 6px;
|
|
245
|
-
padding: 6px 16px;
|
|
246
|
-
}
|
|
247
|
-
`, de = p("div")`
|
|
248
|
-
width: 48px;
|
|
249
|
-
height: 48px;
|
|
250
|
-
margin: 0 auto 16px;
|
|
251
|
-
background-color: #f6f8fa;
|
|
252
|
-
border-radius: 50%;
|
|
253
|
-
display: flex;
|
|
254
|
-
align-items: center;
|
|
255
|
-
justify-content: center;
|
|
256
|
-
|
|
257
|
-
svg {
|
|
258
|
-
width: 32px;
|
|
259
|
-
height: 32px;
|
|
260
|
-
}
|
|
261
|
-
`, pe = p.div`
|
|
262
|
-
display: flex;
|
|
263
|
-
flex-direction: column;
|
|
264
|
-
align-items: center;
|
|
265
|
-
justify-content: center;
|
|
266
|
-
width: 100%;
|
|
267
|
-
gap: 24px;
|
|
268
|
-
|
|
269
|
-
input[type='number']::-webkit-inner-spin-button,
|
|
270
|
-
input[type='number']::-webkit-outer-spin-button {
|
|
271
|
-
-webkit-appearance: none;
|
|
272
|
-
margin: 0;
|
|
273
|
-
}
|
|
274
|
-
div.Mui-focused input {
|
|
275
|
-
caret-color: ${(y) => y.theme.palette.primary.main};
|
|
276
|
-
}
|
|
277
|
-
`;
|
|
278
|
-
export {
|
|
279
|
-
ne as default
|
|
280
|
-
};
|
package/lib/Passkey/icon.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
-
function o(T) {
|
|
3
|
-
return /* @__PURE__ */ t("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, viewBox: "0 0 24 24", ...T, children: /* @__PURE__ */ t(
|
|
4
|
-
"path",
|
|
5
|
-
{
|
|
6
|
-
fill: "currentColor",
|
|
7
|
-
d: "M3 20v-2.8q0-.85.438-1.562T4.6 14.55q1.55-.775 3.15-1.162T11 13q.5 0 1 .038t1 .112q-.1 1.45.525 2.738T15.35 18v2zm16 3l-1.5-1.5v-4.65q-1.1-.325-1.8-1.237T15 13.5q0-1.45 1.025-2.475T18.5 10t2.475 1.025T22 13.5q0 1.125-.638 2t-1.612 1.25L21 18l-1.5 1.5L21 21zm-8-11q-1.65 0-2.825-1.175T7 8t1.175-2.825T11 4t2.825 1.175T15 8t-1.175 2.825T11 12m7.5 2q.425 0 .713-.288T19.5 13t-.288-.712T18.5 12t-.712.288T17.5 13t.288.713t.712.287"
|
|
8
|
-
}
|
|
9
|
-
) });
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
o as default
|
|
13
|
-
};
|
package/lib/Passkey/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PasskeyConsumer as o, PasskeyContext as a, PasskeyProvider as r, usePasskey as t } from "./context.js";
|
|
2
|
-
import { default as k } from "./actions.js";
|
|
3
|
-
export {
|
|
4
|
-
k as PasskeyActions,
|
|
5
|
-
o as PasskeyConsumer,
|
|
6
|
-
a as PasskeyContext,
|
|
7
|
-
r as PasskeyProvider,
|
|
8
|
-
t as usePasskey
|
|
9
|
-
};
|
package/lib/Service/index.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { joinURL as y } from "ufo";
|
|
2
|
-
import { createAxios as m } from "../utils.js";
|
|
3
|
-
async function g(o, { authServicePrefix: s, serviceHost: i }) {
|
|
4
|
-
if (!o)
|
|
5
|
-
throw new Error("Refresh token not found");
|
|
6
|
-
const u = m({
|
|
7
|
-
baseURL: i,
|
|
8
|
-
timeout: 10 * 1e3,
|
|
9
|
-
secure: !0,
|
|
10
|
-
headers: {
|
|
11
|
-
authorization: `Bearer ${encodeURIComponent(o)}`
|
|
12
|
-
}
|
|
13
|
-
}), { data: a } = await u.post(y(s, "/refreshSession"));
|
|
14
|
-
return a;
|
|
15
|
-
}
|
|
16
|
-
function v({
|
|
17
|
-
refreshTokenStorage: o,
|
|
18
|
-
sessionTokenStorage: s,
|
|
19
|
-
serviceHost: i,
|
|
20
|
-
authServicePrefix: u,
|
|
21
|
-
onRefreshTokenError: a,
|
|
22
|
-
onRefreshTokenSuccess: f
|
|
23
|
-
}, k = {}) {
|
|
24
|
-
let n = null;
|
|
25
|
-
const c = m({
|
|
26
|
-
baseURL: i,
|
|
27
|
-
timeout: 30 * 1e3,
|
|
28
|
-
...k
|
|
29
|
-
}), { getToken: h, setToken: p, removeToken: T } = s, { getToken: R, setToken: l, removeToken: d } = o;
|
|
30
|
-
return c.interceptors.request.use(
|
|
31
|
-
async (e) => {
|
|
32
|
-
if (s.engine === "ls") {
|
|
33
|
-
const t = h();
|
|
34
|
-
t && (e.headers.authorization = `Bearer ${encodeURIComponent(t)}`);
|
|
35
|
-
}
|
|
36
|
-
return n && await n, e;
|
|
37
|
-
},
|
|
38
|
-
(e) => Promise.reject(e)
|
|
39
|
-
), c.interceptors.response.use(
|
|
40
|
-
(e) => e,
|
|
41
|
-
async (e) => {
|
|
42
|
-
const t = e.config;
|
|
43
|
-
if (!t)
|
|
44
|
-
return Promise.reject(e);
|
|
45
|
-
if (t.headers = { ...t?.headers }, e?.response?.status === 401 && !t._retry) {
|
|
46
|
-
t._retry = !0, n || (n = g(R(), { serviceHost: i, authServicePrefix: u }));
|
|
47
|
-
try {
|
|
48
|
-
const r = await n;
|
|
49
|
-
return p(r.nextToken), l(r.nextRefreshToken), typeof f == "function" && f(r), c(t);
|
|
50
|
-
} catch (r) {
|
|
51
|
-
return T(), d(), typeof a == "function" && a(), Promise.reject(r);
|
|
52
|
-
} finally {
|
|
53
|
-
n = null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return Promise.reject(e);
|
|
57
|
-
}
|
|
58
|
-
), c;
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
61
|
-
v as default
|
|
62
|
-
};
|