@arcblock/did-connect-react 3.1.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/LICENSE +13 -0
- package/README.md +134 -0
- package/lib/Address/index.js +4 -0
- package/lib/Avatar/index.js +4 -0
- package/lib/Button/index.js +17 -0
- package/lib/Connect/assets/locale.js +143 -0
- package/lib/Connect/assets/login-bg.png +0 -0
- package/lib/Connect/assets/login-slogan.js +9 -0
- package/lib/Connect/components/action-button.js +26 -0
- package/lib/Connect/components/app-tips.js +132 -0
- package/lib/Connect/components/auto-height.js +31 -0
- package/lib/Connect/components/back-button.js +24 -0
- package/lib/Connect/components/connect-status.js +263 -0
- package/lib/Connect/components/did-connect-title.js +126 -0
- package/lib/Connect/components/download-tips.js +52 -0
- package/lib/Connect/components/loading.js +26 -0
- package/lib/Connect/components/login-item/connect-choose-list.js +249 -0
- package/lib/Connect/components/login-item/login-method-item.js +129 -0
- package/lib/Connect/components/login-item/mobile-login-item.js +114 -0
- package/lib/Connect/components/login-item/passkey-login-item.js +44 -0
- package/lib/Connect/components/login-item/web-login-item.js +97 -0
- package/lib/Connect/components/mask-overlay.js +34 -0
- package/lib/Connect/components/refresh-overlay.js +57 -0
- package/lib/Connect/components/switch-app.js +70 -0
- package/lib/Connect/contexts/state.js +142 -0
- package/lib/Connect/fullpage.js +5 -0
- package/lib/Connect/hooks/auth-url.js +23 -0
- package/lib/Connect/hooks/method-list.js +46 -0
- package/lib/Connect/hooks/page-show.js +17 -0
- package/lib/Connect/hooks/security.js +27 -0
- package/lib/Connect/hooks/token.js +305 -0
- package/lib/Connect/hooks/use-apps.js +19 -0
- package/lib/Connect/hooks/use-quick-connect.js +97 -0
- package/lib/Connect/index.js +498 -0
- package/lib/Connect/landing-page.js +5 -0
- package/lib/Connect/plugins/email/index.js +62 -0
- package/lib/Connect/plugins/email/list-item.js +28 -0
- package/lib/Connect/plugins/email/placeholder.js +283 -0
- package/lib/Connect/plugins/index.js +4 -0
- package/lib/Connect/use-connect.js +164 -0
- package/lib/Connect/with-blocklet.js +15 -0
- package/lib/Connect/with-bridge-call.js +108 -0
- package/lib/Federated/context.js +61 -0
- package/lib/Federated/index.js +7 -0
- package/lib/Logo/index.js +4 -0
- package/lib/OAuth/context.js +234 -0
- package/lib/OAuth/guest.svg.js +5 -0
- package/lib/OAuth/index.js +7 -0
- package/lib/OAuth/passport-switcher.js +114 -0
- package/lib/Passkey/actions.js +165 -0
- package/lib/Passkey/constants.js +4 -0
- package/lib/Passkey/context.js +266 -0
- package/lib/Passkey/dialog.js +277 -0
- package/lib/Passkey/icon.js +13 -0
- package/lib/Passkey/index.js +9 -0
- package/lib/Service/index.js +62 -0
- package/lib/Session/assets/did-spaces-guide-cover.svg.js +135 -0
- package/lib/Session/assets/did-spaces-guide-icon.svg.js +9 -0
- package/lib/Session/context.js +5 -0
- package/lib/Session/did-spaces-guide.js +136 -0
- package/lib/Session/hooks/use-federated.js +64 -0
- package/lib/Session/hooks/use-mobile.js +8 -0
- package/lib/Session/hooks/use-protected-routes.js +11 -0
- package/lib/Session/hooks/use-session-token.js +169 -0
- package/lib/Session/hooks/use-verify.js +45 -0
- package/lib/Session/index.js +896 -0
- package/lib/Session/libs/constants.js +15 -0
- package/lib/Session/libs/did-spaces.js +10 -0
- package/lib/Session/libs/federated.js +42 -0
- package/lib/Session/libs/index.js +15 -0
- package/lib/Session/libs/locales.js +161 -0
- package/lib/Session/libs/login-mobile.js +55 -0
- package/lib/Session/window-focus-aware.js +17 -0
- package/lib/SessionManager/index.js +4 -0
- package/lib/Storage/engine/cookie.js +21 -0
- package/lib/Storage/engine/local-storage.js +36 -0
- package/lib/Storage/index.js +23 -0
- package/lib/User/index.js +6 -0
- package/lib/User/use-did.js +59 -0
- package/lib/User/wrap-did.js +13 -0
- package/lib/WebWalletSWKeeper/index.js +5 -0
- package/lib/constant.js +22 -0
- package/lib/error.js +8 -0
- package/lib/hooks/use-locale.js +7 -0
- package/lib/index.js +33 -0
- package/lib/locales/en.js +17 -0
- package/lib/locales/index.js +10 -0
- package/lib/locales/zh.js +17 -0
- package/lib/package.json.js +7 -0
- package/lib/types.d.ts +355 -0
- package/lib/utils.js +214 -0
- package/package.json +84 -0
- package/src/Address/index.jsx +2 -0
- package/src/Avatar/index.jsx +2 -0
- package/src/Button/Button.stories.jsx +7 -0
- package/src/Button/index.jsx +21 -0
- package/src/Connect/Connect.stories.jsx +34 -0
- package/src/Connect/assets/locale.js +145 -0
- package/src/Connect/assets/login-bg.png +0 -0
- package/src/Connect/assets/login-slogan.js +7 -0
- package/src/Connect/components/action-button.jsx +22 -0
- package/src/Connect/components/app-tips.jsx +156 -0
- package/src/Connect/components/auto-height.jsx +38 -0
- package/src/Connect/components/back-button.jsx +23 -0
- package/src/Connect/components/connect-status.jsx +259 -0
- package/src/Connect/components/did-connect-title.jsx +106 -0
- package/src/Connect/components/download-tips.jsx +55 -0
- package/src/Connect/components/loading.jsx +25 -0
- package/src/Connect/components/login-item/connect-choose-list.jsx +304 -0
- package/src/Connect/components/login-item/login-method-item.jsx +118 -0
- package/src/Connect/components/login-item/mobile-login-item.jsx +179 -0
- package/src/Connect/components/login-item/passkey-login-item.jsx +52 -0
- package/src/Connect/components/login-item/web-login-item.jsx +149 -0
- package/src/Connect/components/mask-overlay.jsx +32 -0
- package/src/Connect/components/refresh-overlay.jsx +52 -0
- package/src/Connect/components/switch-app.jsx +69 -0
- package/src/Connect/contexts/state.jsx +219 -0
- package/src/Connect/fullpage.jsx +3 -0
- package/src/Connect/hooks/auth-url.js +31 -0
- package/src/Connect/hooks/method-list.js +121 -0
- package/src/Connect/hooks/page-show.js +24 -0
- package/src/Connect/hooks/security.js +40 -0
- package/src/Connect/hooks/token.js +639 -0
- package/src/Connect/hooks/use-apps.js +69 -0
- package/src/Connect/hooks/use-quick-connect.js +130 -0
- package/src/Connect/index.jsx +600 -0
- package/src/Connect/landing-page.jsx +3 -0
- package/src/Connect/plugins/email/index.jsx +82 -0
- package/src/Connect/plugins/email/list-item.jsx +31 -0
- package/src/Connect/plugins/email/placeholder.jsx +365 -0
- package/src/Connect/plugins/index.js +2 -0
- package/src/Connect/use-connect.jsx +321 -0
- package/src/Connect/with-blocklet.jsx +26 -0
- package/src/Connect/with-bridge-call.jsx +138 -0
- package/src/Federated/context.jsx +93 -0
- package/src/Federated/index.jsx +1 -0
- package/src/Logo/index.jsx +2 -0
- package/src/OAuth/context.jsx +346 -0
- package/src/OAuth/guest.svg +20 -0
- package/src/OAuth/index.jsx +1 -0
- package/src/OAuth/passport-switcher.jsx +133 -0
- package/src/Passkey/actions.jsx +212 -0
- package/src/Passkey/constants.js +2 -0
- package/src/Passkey/context.jsx +381 -0
- package/src/Passkey/dialog.jsx +391 -0
- package/src/Passkey/icon.jsx +10 -0
- package/src/Passkey/index.jsx +2 -0
- package/src/Service/index.jsx +96 -0
- package/src/Session/assets/did-spaces-guide-cover.svg +128 -0
- package/src/Session/assets/did-spaces-guide-icon.svg +7 -0
- package/src/Session/context.jsx +7 -0
- package/src/Session/did-spaces-guide.jsx +173 -0
- package/src/Session/hooks/use-federated.js +88 -0
- package/src/Session/hooks/use-mobile.jsx +6 -0
- package/src/Session/hooks/use-protected-routes.js +16 -0
- package/src/Session/hooks/use-session-token.js +365 -0
- package/src/Session/hooks/use-verify.jsx +76 -0
- package/src/Session/index.jsx +1687 -0
- package/src/Session/libs/constants.js +14 -0
- package/src/Session/libs/did-spaces.js +38 -0
- package/src/Session/libs/federated.js +79 -0
- package/src/Session/libs/index.js +5 -0
- package/src/Session/libs/locales.js +160 -0
- package/src/Session/libs/login-mobile.js +80 -0
- package/src/Session/window-focus-aware.jsx +28 -0
- package/src/SessionManager/index.jsx +2 -0
- package/src/Storage/engine/cookie.js +23 -0
- package/src/Storage/engine/local-storage.js +55 -0
- package/src/Storage/index.js +25 -0
- package/src/User/index.js +4 -0
- package/src/User/use-did.js +80 -0
- package/src/User/wrap-did.jsx +18 -0
- package/src/WebWalletSWKeeper/index.jsx +3 -0
- package/src/constant.js +26 -0
- package/src/error.js +6 -0
- package/src/hooks/use-locale.jsx +6 -0
- package/src/index.js +43 -0
- package/src/locales/en.jsx +15 -0
- package/src/locales/index.jsx +13 -0
- package/src/locales/zh.jsx +15 -0
- package/src/types.d.ts +355 -0
- package/src/utils.js +395 -0
- package/vite.config.mjs +29 -0
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import { jsx as m, jsxs as j, Fragment as Lo } from "react/jsx-runtime";
|
|
2
|
+
import S from "prop-types";
|
|
3
|
+
import Eo from "lodash/omit";
|
|
4
|
+
import Oo from "lodash/pick";
|
|
5
|
+
import be from "lodash/cloneDeep";
|
|
6
|
+
import J from "lodash/isFunction";
|
|
7
|
+
import p from "lodash/isUndefined";
|
|
8
|
+
import _o from "lodash/defaultsDeep";
|
|
9
|
+
import Ro from "js-cookie";
|
|
10
|
+
import Uo from "eventemitter3";
|
|
11
|
+
import No from "p-wait-for";
|
|
12
|
+
import { useTheme as Wo, Typography as Bo, Box as K, CircularProgress as Mo } from "@mui/material";
|
|
13
|
+
import { getVisitorId as $, isUrl as zo, ensureVisitorId as Fo, setVisitorId as Ae } from "@arcblock/ux/lib/Util";
|
|
14
|
+
import ce, { ToastProvider as Ce } from "@arcblock/ux/lib/Toast";
|
|
15
|
+
import Ho from "@arcblock/ux/lib/Center";
|
|
16
|
+
import { useReactive as ke, useCreation as ye, useMemoizedFn as f, usePrevious as Go, useLatest as Te, useUpdateEffect as ae, useMount as Vo } from "ahooks";
|
|
17
|
+
import { joinURL as z } from "ufo";
|
|
18
|
+
import { Icon as jo } from "@iconify/react";
|
|
19
|
+
import Ko from "@iconify-icons/material-symbols/keyboard-double-arrow-right-rounded";
|
|
20
|
+
import $o from "@arcblock/react-hooks/lib/useBrowser";
|
|
21
|
+
import qo from "@arcblock/ux/lib/Dialog/use-confirm";
|
|
22
|
+
import De from "@arcblock/ux/lib/DID";
|
|
23
|
+
import Ie from "@arcblock/ux/lib/Avatar";
|
|
24
|
+
import { getCurrentAppPid as Xo } from "@arcblock/ux/lib/SessionUser/libs/utils";
|
|
25
|
+
import { translate as Qo } from "@arcblock/ux/lib/Locale/util";
|
|
26
|
+
import { getBlockletSDK as Yo, BlockletSDK as Jo } from "@blocklet/js-sdk";
|
|
27
|
+
import P from "@arcblock/bridge";
|
|
28
|
+
import { getFederatedEnabled as Zo } from "@arcblock/ux/lib/Util/federated";
|
|
29
|
+
import ei from "lodash/noop";
|
|
30
|
+
import oi from "lodash/isNil";
|
|
31
|
+
import { useState as ii } from "react";
|
|
32
|
+
import ve from "../Storage/index.js";
|
|
33
|
+
import { getBrowserLang as ti, debug as u, decodeUrlParams as xe, sleep as L, updateConnectedInfo as Z, getAppId as ee, logger as Le, formatCacheTtl as ri } from "../utils.js";
|
|
34
|
+
import Ee from "./window-focus-aware.js";
|
|
35
|
+
import { OAuthContext as ni, OAuthConsumer as si, OAuthProvider as Oe, useOAuth as ci } from "../OAuth/context.js";
|
|
36
|
+
import { PasskeyContext as ai, PasskeyConsumer as li, PasskeyProvider as _e, usePasskey as di } from "../Passkey/context.js";
|
|
37
|
+
import "../Passkey/actions.js";
|
|
38
|
+
import pi, { getWalletDid as fi } from "../User/use-did.js";
|
|
39
|
+
import ui from "../User/wrap-did.js";
|
|
40
|
+
import wi from "./hooks/use-federated.js";
|
|
41
|
+
import hi from "./hooks/use-session-token.js";
|
|
42
|
+
import mi from "./hooks/use-protected-routes.js";
|
|
43
|
+
import { SessionContext as ze } from "./context.js";
|
|
44
|
+
import gi from "../Connect/use-connect.js";
|
|
45
|
+
import { EVENTS as w } from "./libs/constants.js";
|
|
46
|
+
import { translations as W } from "./libs/locales.js";
|
|
47
|
+
import { NotOpenError as Si } from "../error.js";
|
|
48
|
+
import { SESSION_TOKEN_STORAGE_KEY as Fe, REFRESH_TOKEN_STORAGE_KEY as He, API_DID_PREFIX as Pi, DEFAULT_TIMEOUT as bi, BLOCKLET_SERVICE_PATH_PREFIX as F, DID_SPACES_BASE_URL as Ai } from "../constant.js";
|
|
49
|
+
import { getMobileVisitorId as Ci, checkEnableAutoLogin as ki, login as yi } from "./libs/login-mobile.js";
|
|
50
|
+
import Ti from "../Connect/hooks/use-quick-connect.js";
|
|
51
|
+
import { didSpacesIsRequired as Re } from "./libs/did-spaces.js";
|
|
52
|
+
import Di from "./did-spaces-guide.js";
|
|
53
|
+
import { FederatedProvider as Ii, useFederatedContext as vi } from "../Federated/context.js";
|
|
54
|
+
import xi from "./hooks/use-verify.js";
|
|
55
|
+
import { loginFederatedMaster as Rt, mountFederatedIframe as Ut } from "./libs/federated.js";
|
|
56
|
+
const Ue = Yo(), { Provider: Li, Consumer: Ne } = ze, We = {
|
|
57
|
+
en: "DID Connect timeout, please reopen DID Connect popup",
|
|
58
|
+
zh: "DID Connect 超时, 请重新打开 DID Connect"
|
|
59
|
+
}, Be = {
|
|
60
|
+
en: "DID Connect is already opened, please wait for it to complete",
|
|
61
|
+
zh: "DID Connect 已打开,请等待完成"
|
|
62
|
+
};
|
|
63
|
+
function Me(q = Fe, X = "ls", oe = {}, k = {}) {
|
|
64
|
+
let v = "/";
|
|
65
|
+
globalThis?.blocklet?.prefix && (v = globalThis.blocklet.prefix), typeof k == "boolean" && (k = {
|
|
66
|
+
appendAuthServicePrefix: k,
|
|
67
|
+
extraParams: {}
|
|
68
|
+
}), _o(k, {
|
|
69
|
+
rolling: !0,
|
|
70
|
+
appendAuthServicePrefix: !1,
|
|
71
|
+
extraParams: {},
|
|
72
|
+
refreshTokenStorageKey: He
|
|
73
|
+
});
|
|
74
|
+
function O(D) {
|
|
75
|
+
if (globalThis.blocklet)
|
|
76
|
+
if (D?.user) {
|
|
77
|
+
const r = {
|
|
78
|
+
did: D.user.did,
|
|
79
|
+
host: window.location.host,
|
|
80
|
+
appPid: globalThis.blocklet.appPid,
|
|
81
|
+
visitorId: $(),
|
|
82
|
+
sourceAppPid: D.user.sourceAppPid,
|
|
83
|
+
fullName: D.user.fullName
|
|
84
|
+
};
|
|
85
|
+
u("bridge callArc: onLogin", r), P.callArc("onLogin", { ...r, user: r });
|
|
86
|
+
} else
|
|
87
|
+
P.callArc("onLogin", { error: "no user", code: 400 }), u("notifyBridge failed", { sessionState: D });
|
|
88
|
+
}
|
|
89
|
+
const Q = ve(q, X, oe), H = ve(k.refreshTokenStorageKey, "ls");
|
|
90
|
+
function le({ ...D }) {
|
|
91
|
+
const r = Object.assign({}, D);
|
|
92
|
+
p(r.serviceHost) && (r.serviceHost = v), p(r.locale) && (r.locale = ""), p(r.action) && (r.action = "login"), p(r.prefix) && (r.prefix = Pi), p(r.appendAuthServicePrefix) && (r.appendAuthServicePrefix = !1), p(r.extraParams) && (r.extraParams = {}), p(r.options) && (r.options = {}), p(r.autoConnect) && (r.autoConnect = !1), p(r.autoDisconnect) && (r.autoDisconnect = !0), p(r.useSocket) && (r.useSocket = !0), p(r.timeout) && (r.timeout = bi * 1e3), p(r.webWalletUrl) && (r.webWalletUrl = void 0), p(r.protectedRoutes) && (r.protectedRoutes = ["*"]), p(r.apiOptions) && (r.apiOptions = {}), p(r.lazyRefreshToken) && (r.lazyRefreshToken = !1);
|
|
93
|
+
const { connectApi: y, connectHolder: ie } = gi(), [Ve, de] = ii(0), T = $o(), { requestStorageAccess: je } = vi(), { palette: Ke } = Wo(), B = new URLSearchParams(window.location.search), s = ke({
|
|
94
|
+
extraParams: {},
|
|
95
|
+
options: {},
|
|
96
|
+
currentLocale: r.locale,
|
|
97
|
+
allowWallet: void 0,
|
|
98
|
+
openMode: "window",
|
|
99
|
+
get autoConnect() {
|
|
100
|
+
return typeof r.autoConnect == "boolean" ? r.autoConnect : !!r.autoLogin;
|
|
101
|
+
},
|
|
102
|
+
get prefix() {
|
|
103
|
+
return k.appendAuthServicePrefix || r.appendAuthServicePrefix ? z(F, r.prefix) : r.prefix;
|
|
104
|
+
},
|
|
105
|
+
get notificationPrefix() {
|
|
106
|
+
const e = "/api/notifications";
|
|
107
|
+
return k.appendAuthServicePrefix || r.appendAuthServicePrefix ? z(F, e) : e;
|
|
108
|
+
}
|
|
109
|
+
}), t = ke({
|
|
110
|
+
action: r.action,
|
|
111
|
+
error: "",
|
|
112
|
+
initialized: !1,
|
|
113
|
+
loading: !1,
|
|
114
|
+
open: !1,
|
|
115
|
+
user: null,
|
|
116
|
+
provider: "",
|
|
117
|
+
walletOS: "",
|
|
118
|
+
baseUrl: "",
|
|
119
|
+
unReadCount: 0
|
|
120
|
+
// 不可以直接个性 props.autoConnect (readonly)
|
|
121
|
+
}), b = ye(() => r.locale || s.currentLocale || ti(), [r.locale, s.currentLocale]), { confirmApi: $e, confirmHolder: qe } = qo(), _ = f(() => {
|
|
122
|
+
if (t.open && !T.arcSphere) {
|
|
123
|
+
const e = Be[b] || Be.en;
|
|
124
|
+
throw ce.warning(e), new Error(e);
|
|
125
|
+
}
|
|
126
|
+
}), g = ye(() => new Uo(), []), M = f((e, o, i) => {
|
|
127
|
+
const n = {
|
|
128
|
+
login: [w.LOGIN, w.CANCEL_LOGIN],
|
|
129
|
+
"bind-wallet": [w.BIND_WALLET, w.CANCEL_BIND_WALLET],
|
|
130
|
+
"switch-passport": [w.SWITCH_PASSPORT, w.CANCEL_SWITCH_PASSPORT],
|
|
131
|
+
"switch-profile": [w.SWITCH_PROFILE, w.CANCEL_SWITCH_PROFILE],
|
|
132
|
+
// HACK: 对于内部来说,switch-did 就是 login,所以内部的监听事件仍然是 login
|
|
133
|
+
"switch-did": [w.LOGIN, w.CANCEL_LOGIN],
|
|
134
|
+
// @FIXME: @zhanghan 整个事件发射的机制需要重构,目前的实现不是很优雅,对于用户来说不是很好用。 https://github.com/ArcBlock/ux/pull/1414#discussion_r1904830954
|
|
135
|
+
"did-space-connected": [w.DID_SPACE_CONNECTED]
|
|
136
|
+
};
|
|
137
|
+
if (!Object.keys(n).includes(e))
|
|
138
|
+
return;
|
|
139
|
+
const a = async (...d) => {
|
|
140
|
+
J(o) && await o(...d), g.emit(e, ...d);
|
|
141
|
+
};
|
|
142
|
+
g.once(n[e][0], a), g.once(n[e][1], async (...d) => {
|
|
143
|
+
J(a) && g.off(n[e][0], a), J(i) && await i(...d), g.emit(`cancel-${e}`, ...d);
|
|
144
|
+
});
|
|
145
|
+
}), Xe = Go(t.initialized, (e, o) => e !== o || e === !0 && o === !0), {
|
|
146
|
+
syncSessionSate: Qe,
|
|
147
|
+
handleRefreshUser: A,
|
|
148
|
+
handleRefreshToken: Ye,
|
|
149
|
+
renewToken: Je,
|
|
150
|
+
clearSession: pe,
|
|
151
|
+
handleLoginResult: E,
|
|
152
|
+
decrypt: x,
|
|
153
|
+
service: Ze,
|
|
154
|
+
getSessionToken: eo,
|
|
155
|
+
getRefreshToken: oo,
|
|
156
|
+
setRefreshToken: io,
|
|
157
|
+
setSessionToken: to
|
|
158
|
+
} = hi({
|
|
159
|
+
state: t,
|
|
160
|
+
pageState: s,
|
|
161
|
+
sessionTokenStorage: Q,
|
|
162
|
+
refreshTokenStorage: H,
|
|
163
|
+
serviceHost: r.serviceHost,
|
|
164
|
+
apiOptions: r.apiOptions,
|
|
165
|
+
lazyRefreshToken: r.lazyRefreshToken,
|
|
166
|
+
onRefresh({ type: e, sessionToken: o, refreshToken: i, user: n }) {
|
|
167
|
+
if (u("onRefresh", { type: e, user: n }), globalThis.blocklet) {
|
|
168
|
+
const a = {
|
|
169
|
+
did: n.did,
|
|
170
|
+
host: window.location.host,
|
|
171
|
+
appPid: globalThis.blocklet.appPid,
|
|
172
|
+
visitorId: $(),
|
|
173
|
+
sourceAppPid: n.sourceAppPid,
|
|
174
|
+
fullName: n.fullName
|
|
175
|
+
};
|
|
176
|
+
e === "refreshToken" ? (u("bridge callArc: onRefreshToken"), P.callArc("onRefreshToken", {
|
|
177
|
+
sessionToken: o,
|
|
178
|
+
refreshToken: i,
|
|
179
|
+
user: a
|
|
180
|
+
})) : e === "refreshUser" && (u("bridge callArc: onRefreshUser"), P.callArc("onRefreshUser", {
|
|
181
|
+
sessionToken: o,
|
|
182
|
+
refreshToken: i,
|
|
183
|
+
user: a
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}), ro = xi({ state: t, connectApi: y }), fe = f((e, o = {}, i = {}) => {
|
|
188
|
+
_();
|
|
189
|
+
const n = e;
|
|
190
|
+
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}, i.origin = n.origin || ""), (!t.user || i.origin === "switch-did") && (i.origin === "switch-did" ? M("switch-did", e, n?.onCancel) : M("login", e, n?.onCancel), s.extraParams = o, s.options = i, t.action = "login", N());
|
|
191
|
+
}), no = f((e, o = {}) => {
|
|
192
|
+
const i = e;
|
|
193
|
+
return function(...a) {
|
|
194
|
+
const d = this;
|
|
195
|
+
return (async () => {
|
|
196
|
+
try {
|
|
197
|
+
const l = await ro(o);
|
|
198
|
+
if (!l.sessionId)
|
|
199
|
+
throw new Error("Authentication failed");
|
|
200
|
+
return await i.call(d, l, ...a);
|
|
201
|
+
} catch (l) {
|
|
202
|
+
throw console.error("Authentication failed", l), l;
|
|
203
|
+
}
|
|
204
|
+
})();
|
|
205
|
+
};
|
|
206
|
+
}), te = f(async (e, o = {}, i = {}) => {
|
|
207
|
+
_();
|
|
208
|
+
const n = e;
|
|
209
|
+
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}), p(o?.inviter) && window.localStorage.getItem("inviter") && (o.inviter = window.localStorage.getItem("inviter"));
|
|
210
|
+
const { params: a } = await xe();
|
|
211
|
+
if (p(o?.forceConnected) && a?.forceConnected && (o.forceConnected = a.forceConnected, p(i.showQuickConnect) && (i.showQuickConnect = !1)), p(o?.sourceAppPid) && !p(a?.sourceAppPid) && (o.sourceAppPid = a.sourceAppPid), o?.openMode === "redirect") {
|
|
212
|
+
const h = o?.redirect || "/", I = new URL(`${F}/login`, window.location.origin);
|
|
213
|
+
I.searchParams.set("redirect", h), o?.forceConnected && I.searchParams.set("forceConnected", o?.forceConnected), p(o?.sourceAppPid) || I.searchParams.set("sourceAppPid", o?.sourceAppPid), p(o?.inviter) || I.searchParams.set("inviter", o?.inviter), i?.origin && I.searchParams.set("origin", i.origin), window.location.href = I.href;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
let d = o?.sourceAppPid;
|
|
217
|
+
p(d) && bo && (d = Ao.appPid), await No(() => t.initialized), typeof i == "string" && (i = { origin: i });
|
|
218
|
+
const l = be(o);
|
|
219
|
+
l.passkeyBehavior = "both", s.allowWallet = void 0;
|
|
220
|
+
const c = l?.openMode || r?.extraParams?.openMode;
|
|
221
|
+
p(c) ? d ? d !== globalThis.blocklet.appPid && Zo(globalThis.blocklet) && (s.openMode = "window") : s.openMode = "popup" : s.openMode = c, s.openMode === "window" && !T.arcSphere && !T.wallet && await je() && (s.openMode = "popup"), d ? t.baseUrl = globalThis.blocklet.appUrl : t.baseUrl = "", fe(e, l, i);
|
|
222
|
+
}), ue = f(async (e) => {
|
|
223
|
+
const o = $();
|
|
224
|
+
if (globalThis.blocklet && (Ue.user.logout({ visitorId: o }).catch((i) => {
|
|
225
|
+
console.warn("Failed to logout remote", i);
|
|
226
|
+
}), await L(100)), globalThis.blocklet) {
|
|
227
|
+
const i = {
|
|
228
|
+
visitorId: o,
|
|
229
|
+
appPid: globalThis.blocklet.appPid,
|
|
230
|
+
userDid: t.user.did
|
|
231
|
+
};
|
|
232
|
+
u("bridge callArc: onLogout", i), P.callArc("onLogout", i);
|
|
233
|
+
}
|
|
234
|
+
pe(), V(), t.user = null, t.provider = "", t.walletOS = "", t.error = "", t.loading = !1, g.emit("logout"), typeof e == "function" && e();
|
|
235
|
+
}), {
|
|
236
|
+
userSessions: so,
|
|
237
|
+
refresh: co,
|
|
238
|
+
loaded: ao,
|
|
239
|
+
loginUserSession: re
|
|
240
|
+
} = Ti({
|
|
241
|
+
appPid: Xo(t.user),
|
|
242
|
+
loginAppPid: globalThis?.blocklet?.appPid,
|
|
243
|
+
sourceAppPid: t?.user?.sourceAppPid,
|
|
244
|
+
autoFetch: !1,
|
|
245
|
+
fetchAll: !0
|
|
246
|
+
}), R = f(async () => {
|
|
247
|
+
t?.user || await new Promise((e) => {
|
|
248
|
+
te(() => {
|
|
249
|
+
e();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}), ne = f((e, o = {}, i = {}) => {
|
|
253
|
+
_();
|
|
254
|
+
const n = e;
|
|
255
|
+
typeof n == "object" && (e = n.onSuccess, o = n.extraParams || {}, i = n.options || {}), typeof i == "string" && (i = { origin: i }), i?.userSession ? re(i.userSession).then((a) => {
|
|
256
|
+
Z(
|
|
257
|
+
{
|
|
258
|
+
connected_did: i.userSession.user.did,
|
|
259
|
+
connected_pk: i.userSession.user.pk,
|
|
260
|
+
connected_wallet_os: i.userSession.extra.walletOS,
|
|
261
|
+
connected_app: ee()
|
|
262
|
+
},
|
|
263
|
+
!0
|
|
264
|
+
), M("switch-did", e), E({ ...a, encrypted: !1 }), A({ showProgress: !0 }).then(async () => {
|
|
265
|
+
await L(200), g.emit(w.LOGIN, a, x, C.current), O(C.current), await U();
|
|
266
|
+
});
|
|
267
|
+
}) : (p(o?.forceConnected) && (o.forceConnected = !1), o.passkeyBehavior = "both", te(e, o, { ...i, origin: "switch-did" }));
|
|
268
|
+
}), lo = f(async () => {
|
|
269
|
+
await Ue.user.refreshProfile();
|
|
270
|
+
}), po = f(async (e, o = {}) => {
|
|
271
|
+
await R(), _();
|
|
272
|
+
const i = e;
|
|
273
|
+
typeof i == "object" && (e = i.onSuccess, o = i.extraParams || {}), M("switch-profile", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "switch-profile", N();
|
|
274
|
+
}), fo = f(async (e, o = {}) => {
|
|
275
|
+
await R(), _();
|
|
276
|
+
const i = e;
|
|
277
|
+
typeof i == "object" && (e = i.onSuccess, o = i.extraParams || {}), M("switch-passport", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "switch-passport", N();
|
|
278
|
+
}), uo = f(async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
279
|
+
}, ...i } = {}) => {
|
|
280
|
+
await R(), _(), s.extraParams = {
|
|
281
|
+
referrer: window.location.href,
|
|
282
|
+
purpose: "authorize-for-import",
|
|
283
|
+
...e,
|
|
284
|
+
saveConnect: !1
|
|
285
|
+
// 连接 spaces 不保存连接信息
|
|
286
|
+
}, s.options = {}, t.action = "connect-to-did-spaces-for-user", N({
|
|
287
|
+
hideCloseButton: !0,
|
|
288
|
+
onSuccess: o,
|
|
289
|
+
...i
|
|
290
|
+
});
|
|
291
|
+
}), we = f(async ({ extraParams: e = {}, onSuccess: o = {} } = {}) => {
|
|
292
|
+
await R(), uo({
|
|
293
|
+
extraParams: {
|
|
294
|
+
// service 交互
|
|
295
|
+
purpose: "authorize-for-import",
|
|
296
|
+
...e
|
|
297
|
+
},
|
|
298
|
+
onSuccess: o,
|
|
299
|
+
hideCloseButton: !1
|
|
300
|
+
});
|
|
301
|
+
}), { didSpacesGuideApi: Y, DidSpacesGuideView: wo } = Di({
|
|
302
|
+
autoClose: !1
|
|
303
|
+
}), U = async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
304
|
+
} } = {}) => {
|
|
305
|
+
await R(), await Re(t?.user) && (Y.open(), Y.onConnect((i = ei) => {
|
|
306
|
+
const n = {
|
|
307
|
+
prefix: "/connect-to-did-space",
|
|
308
|
+
custom: !0,
|
|
309
|
+
extraParams: {
|
|
310
|
+
provider: "wallet",
|
|
311
|
+
appPid: window.blocklet?.appPid,
|
|
312
|
+
appDid: window.blocklet?.appId,
|
|
313
|
+
appName: window.blocklet?.appName,
|
|
314
|
+
appDescription: window.blocklet?.appDescription,
|
|
315
|
+
appUrl: window.blocklet?.appUrl,
|
|
316
|
+
referrer: window.location.href,
|
|
317
|
+
connectScope: "user",
|
|
318
|
+
...e
|
|
319
|
+
},
|
|
320
|
+
onSuccess: async (a, d) => {
|
|
321
|
+
const l = d ? d(a.spaceGateway) : a.spaceGateway;
|
|
322
|
+
await new Jo().user.updateDidSpace({ spaceGateway: l }), await A({ showProgress: !0 }), await o(a, d), await Y.close(), g.emit(w.DID_SPACE_CONNECTED, a, d), globalThis.blocklet && (u("bridge callArc: onDidSpaceConnected"), P.callArc("onDidSpaceConnected")), i(!0);
|
|
323
|
+
},
|
|
324
|
+
onError: (a) => {
|
|
325
|
+
console.error(a), ce.error(a.message), Y.close(), i(!1);
|
|
326
|
+
},
|
|
327
|
+
onClose: () => {
|
|
328
|
+
i();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
y.openPopup(n, {
|
|
332
|
+
baseUrl: Ai
|
|
333
|
+
});
|
|
334
|
+
}));
|
|
335
|
+
}, he = f(async (e, o = {}) => {
|
|
336
|
+
if (await R(), fi(t.user)) {
|
|
337
|
+
e({}, x, C.current);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
_();
|
|
341
|
+
const i = e;
|
|
342
|
+
typeof i == "object" && (e = i.onSuccess), M("bind-wallet", e, i?.onCancel), s.extraParams = o, s.options = {}, t.action = "bind-wallet", N();
|
|
343
|
+
}), se = f(async (e) => {
|
|
344
|
+
u("onSwitchPassport", { result: e }), s.extraParams = {}, s.options = {}, E(e), t.loading = !1, await A({ showProgress: !0 }), await L(200), g.emit(w.SWITCH_PASSPORT, e, x, C.current), globalThis.blocklet && (u("bridge callArc: onSwitchPassport"), P.callArc("onSwitchPassport"));
|
|
345
|
+
}), G = f(async (e) => {
|
|
346
|
+
if (t.action === "switch-passport") {
|
|
347
|
+
se(e);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
u("onLogin", { result: e }), s.extraParams = {}, s.options = {}, E(e), t.loading = !1, await A({ showProgress: !0 }), await L(200), t.action === "login" && (u("onLogin: emit LOGIN event", { result: e }), g.emit(w.LOGIN, e, x, C.current), O(C.current), U());
|
|
351
|
+
}), ho = f((e) => {
|
|
352
|
+
s.extraParams = {}, s.options = {}, E(e), t.loading = !1, A({ showProgress: !0 }).then(async () => {
|
|
353
|
+
await L(100), g.emit(w.BIND_WALLET, e, x, C.current), globalThis.blocklet && (u("bridge callArc: onBindWallet"), P.callArc("onBindWallet"));
|
|
354
|
+
});
|
|
355
|
+
}), mo = f((e) => {
|
|
356
|
+
u("onSwitchProfile", { result: e }), s.extraParams = {}, s.options = {}, t.loading = !1, A({ showProgress: !0 }).then(async () => {
|
|
357
|
+
await L(100), g.emit(w.SWITCH_PROFILE, e, x, C.current), globalThis.blocklet && (u("bridge callArc: onSwitchProfile"), P.callArc("onSwitchProfile"));
|
|
358
|
+
});
|
|
359
|
+
}), go = f((e) => {
|
|
360
|
+
s.extraParams = {}, s.options = {}, V();
|
|
361
|
+
const o = {
|
|
362
|
+
login: w.CANCEL_LOGIN,
|
|
363
|
+
"switch-profile": w.CANCEL_SWITCH_PROFILE,
|
|
364
|
+
"switch-passport": w.CANCEL_SWITCH_PASSPORT,
|
|
365
|
+
"bind-wallet": w.CANCEL_BIND_WALLET
|
|
366
|
+
}, i = {
|
|
367
|
+
login: "offLogin",
|
|
368
|
+
"switch-profile": "offSwitchProfile",
|
|
369
|
+
"switch-passport": "offSwitchPassport",
|
|
370
|
+
"bind-wallet": "offBindWallet"
|
|
371
|
+
};
|
|
372
|
+
g.emit(o[e]), globalThis.blocklet && (u(`bridge callArc: ${i[e]}`), P.callArc(`${i[e]}`));
|
|
373
|
+
}), So = f((e, ...o) => {
|
|
374
|
+
try {
|
|
375
|
+
vo[e](...o);
|
|
376
|
+
} catch (i) {
|
|
377
|
+
Le.error("Catch error in onSuccess", {
|
|
378
|
+
action: e,
|
|
379
|
+
args: o,
|
|
380
|
+
err: i
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}), {
|
|
384
|
+
federatedMaster: Po,
|
|
385
|
+
federatedEnabled: bo,
|
|
386
|
+
master: Ao
|
|
387
|
+
} = wi({
|
|
388
|
+
locale: b,
|
|
389
|
+
decrypt: x,
|
|
390
|
+
login: fe,
|
|
391
|
+
handleLoginResult: E,
|
|
392
|
+
handleRefreshUser: A,
|
|
393
|
+
setRefreshToken: io,
|
|
394
|
+
setSessionToken: to
|
|
395
|
+
}), { checkMatch: Co } = mi({ protectedRoutes: r.protectedRoutes || [] }), ko = Te(so), me = f(async () => (ao || (await co(), await L(100)), ko.current)), V = f(() => {
|
|
396
|
+
t.open = !1, y.close();
|
|
397
|
+
}), N = async (e = {}) => {
|
|
398
|
+
let o = t.action;
|
|
399
|
+
s?.options?.origin === "switch-did" && (o = s?.options?.origin);
|
|
400
|
+
const i = W[o], n = i[b] || i.en, a = {
|
|
401
|
+
...k.extraParams,
|
|
402
|
+
...r.extraParams,
|
|
403
|
+
...s.extraParams,
|
|
404
|
+
previousUserDid: t?.user?.did,
|
|
405
|
+
email: t?.user?.email
|
|
406
|
+
};
|
|
407
|
+
if (o === "switch-did" && a?.forceConnected) {
|
|
408
|
+
const l = (c, h = {}) => Qo(W["switch-specified-did"], c, b, "en", h);
|
|
409
|
+
n.title = l("title"), n.scan = l("scan", { did: a.forceConnected }), n.confirm = l("confirm"), n.success = l("success");
|
|
410
|
+
}
|
|
411
|
+
delete a?.openMode;
|
|
412
|
+
const d = {
|
|
413
|
+
action: t.action,
|
|
414
|
+
locale: b,
|
|
415
|
+
hideCloseButton: e?.hideCloseButton,
|
|
416
|
+
extraParams: a,
|
|
417
|
+
options: { ...r.options || {}, ...s.options },
|
|
418
|
+
checkTimeout: r.timeout,
|
|
419
|
+
webWalletUrl: r.webWalletUrl,
|
|
420
|
+
messages: n,
|
|
421
|
+
useSocket: r.useSocket,
|
|
422
|
+
...Eo(r, [
|
|
423
|
+
"action",
|
|
424
|
+
"locale",
|
|
425
|
+
// NOTICE: 将 serviceHost 也透传给 DID Connect 组件
|
|
426
|
+
// 'serviceHost',
|
|
427
|
+
"appendAuthServicePrefix",
|
|
428
|
+
"autoDisconnect",
|
|
429
|
+
"children",
|
|
430
|
+
"timeout",
|
|
431
|
+
"extraParams",
|
|
432
|
+
"options",
|
|
433
|
+
"webWalletUrl",
|
|
434
|
+
"messages",
|
|
435
|
+
"useSocket",
|
|
436
|
+
"lazyRefreshToken",
|
|
437
|
+
"apiOptions",
|
|
438
|
+
"protectedRoutes"
|
|
439
|
+
]),
|
|
440
|
+
// 允许 login/switchProfile/switchDid 的时候传入自定义参数
|
|
441
|
+
...Oo(s.extraParams || {}, [
|
|
442
|
+
"autoConnect",
|
|
443
|
+
"forceConnected",
|
|
444
|
+
"saveConnect",
|
|
445
|
+
"useSocket",
|
|
446
|
+
"passkeyBehavior"
|
|
447
|
+
]),
|
|
448
|
+
// baseUrl: state.baseUrl || props.baseUrl || '',
|
|
449
|
+
// 注意 prefix 经过了特殊处理, 优先级高于 "...rest", 所以放在其后
|
|
450
|
+
prefix: s.prefix,
|
|
451
|
+
allowWallet: p(s.allowWallet) ? t.action !== "login" || ["1", "true", void 0, null].includes(globalThis.blocklet?.DID_CONNECT_ALLOW_WALLET) : s.allowWallet,
|
|
452
|
+
onSuccess: async (...l) => {
|
|
453
|
+
So(t.action, ...l), J(e?.onSuccess) && await e.onSuccess(...l), t.open = !1;
|
|
454
|
+
},
|
|
455
|
+
onClose(...l) {
|
|
456
|
+
go(t.action, ...l);
|
|
457
|
+
},
|
|
458
|
+
onError(l) {
|
|
459
|
+
console.error(l);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
if (t.open = !0, ["login"].includes(t.action) && s.openMode === "window" && !(T.wallet || T.arcSphere))
|
|
463
|
+
try {
|
|
464
|
+
const l = {
|
|
465
|
+
...d,
|
|
466
|
+
baseUrl: window.location.origin
|
|
467
|
+
};
|
|
468
|
+
zo(s.prefix) || (l.prefix = z(window.location.origin, r.serviceHost, s.prefix)), l.extraParams?.provider || (l.extraParams.provider = t?.user?.provider || "wallet"), await y.openPopup(l, { locale: b });
|
|
469
|
+
} catch (l) {
|
|
470
|
+
l instanceof Si && V(), l.message === "Timeout" ? ce.error(We[b] || We.en) : console.error(l);
|
|
471
|
+
}
|
|
472
|
+
else
|
|
473
|
+
y.open(d);
|
|
474
|
+
}, ge = f(async () => {
|
|
475
|
+
const { params: e, url: o } = await xe();
|
|
476
|
+
if (e) {
|
|
477
|
+
const { switchBehavior: i, forceConnected: n, sourceAppPid: a, showClose: d } = e;
|
|
478
|
+
n === t.user.did ? window.history.replaceState(null, "trim", o) : i === "required" ? ne(() => {
|
|
479
|
+
}, {
|
|
480
|
+
openMode: "redirect",
|
|
481
|
+
redirect: o,
|
|
482
|
+
sourceAppPid: a,
|
|
483
|
+
forceConnected: n
|
|
484
|
+
}) : i === "disabled" ? window.history.replaceState(null, "trim", o) : $e.open({
|
|
485
|
+
title: W.switchAccountDialog[b].title,
|
|
486
|
+
content: /* @__PURE__ */ j(Lo, { children: [
|
|
487
|
+
/* @__PURE__ */ m(Bo, { variant: "body1", sx: { textAlign: "center", mb: 2 }, children: W.switchAccountDialog[b].description }),
|
|
488
|
+
/* @__PURE__ */ j(K, { sx: { display: "flex", alignItems: "center", color: "grey.A700" }, children: [
|
|
489
|
+
/* @__PURE__ */ j(
|
|
490
|
+
K,
|
|
491
|
+
{
|
|
492
|
+
sx: {
|
|
493
|
+
display: "flex",
|
|
494
|
+
flexDirection: "column",
|
|
495
|
+
alignItems: "center",
|
|
496
|
+
gap: 1.5,
|
|
497
|
+
lineHeight: 1
|
|
498
|
+
},
|
|
499
|
+
children: [
|
|
500
|
+
/* @__PURE__ */ m(Ie, { did: t.user.did, shape: "circle", variant: "circle", size: 80 }),
|
|
501
|
+
/* @__PURE__ */ m(De, { did: t.user.did, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
502
|
+
W.switchAccountDialog[b].currentAccount
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
),
|
|
506
|
+
/* @__PURE__ */ m(K, { sx: { display: "flex", justifyContent: "center", px: 2 }, children: /* @__PURE__ */ m(
|
|
507
|
+
K,
|
|
508
|
+
{
|
|
509
|
+
component: jo,
|
|
510
|
+
icon: Ko,
|
|
511
|
+
sx: {
|
|
512
|
+
fontSize: 24,
|
|
513
|
+
color: Ke.grey[400],
|
|
514
|
+
animation: "right 2.5s linear infinite",
|
|
515
|
+
"@keyframes right": {
|
|
516
|
+
"0%": {
|
|
517
|
+
transform: "translateX(-3px)",
|
|
518
|
+
opacity: 0
|
|
519
|
+
},
|
|
520
|
+
"60%": {
|
|
521
|
+
transform: "translateX(3px)",
|
|
522
|
+
opacity: 1
|
|
523
|
+
},
|
|
524
|
+
"100%": {
|
|
525
|
+
transform: "translateX(0px)",
|
|
526
|
+
opacity: 0
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
) }),
|
|
532
|
+
/* @__PURE__ */ j(
|
|
533
|
+
K,
|
|
534
|
+
{
|
|
535
|
+
sx: {
|
|
536
|
+
display: "flex",
|
|
537
|
+
flexDirection: "column",
|
|
538
|
+
alignItems: "center",
|
|
539
|
+
gap: 1.5,
|
|
540
|
+
lineHeight: 1,
|
|
541
|
+
fontWeight: 500
|
|
542
|
+
},
|
|
543
|
+
children: [
|
|
544
|
+
/* @__PURE__ */ m(Ie, { did: n, shape: "circle", variant: "circle", size: 80 }),
|
|
545
|
+
/* @__PURE__ */ m(De, { did: n, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
546
|
+
W.switchAccountDialog[b].nextAccount
|
|
547
|
+
]
|
|
548
|
+
}
|
|
549
|
+
)
|
|
550
|
+
] })
|
|
551
|
+
] }),
|
|
552
|
+
showCloseButton: d,
|
|
553
|
+
showCancelButton: !1,
|
|
554
|
+
confirmButtonText: W.switchAccountDialog[b].confirm,
|
|
555
|
+
async onConfirm(l) {
|
|
556
|
+
const h = (await me()).find((I) => I.userDid === n);
|
|
557
|
+
if (h) {
|
|
558
|
+
re(h).then((I) => {
|
|
559
|
+
Z(
|
|
560
|
+
{
|
|
561
|
+
connected_did: h.user.did,
|
|
562
|
+
connected_pk: h.user.pk,
|
|
563
|
+
connected_wallet_os: h.extra.walletOS,
|
|
564
|
+
connected_app: ee()
|
|
565
|
+
},
|
|
566
|
+
!0
|
|
567
|
+
), E({ ...I, encrypted: !1 }), A({ showProgress: !0 }).then(async () => {
|
|
568
|
+
await L(200), g.emit(w.LOGIN, I, x, C.current), O(C.current), await U();
|
|
569
|
+
});
|
|
570
|
+
}), l();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
ne(
|
|
574
|
+
() => {
|
|
575
|
+
l(), window.location.replace(o);
|
|
576
|
+
},
|
|
577
|
+
{ sourceAppPid: a, forceConnected: n, enableSwitchApp: !1 },
|
|
578
|
+
{ showQuickConnect: !0 }
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}), yo = f(async (e, o) => {
|
|
584
|
+
const i = Object.assign(
|
|
585
|
+
{
|
|
586
|
+
login: !0,
|
|
587
|
+
bindWallet: !0,
|
|
588
|
+
bindDidSpaces: !1
|
|
589
|
+
},
|
|
590
|
+
o?.requirements
|
|
591
|
+
), n = o?.openMode || "popup";
|
|
592
|
+
i.login && await R(), i.bindWallet && await new Promise((a) => {
|
|
593
|
+
he(() => {
|
|
594
|
+
a();
|
|
595
|
+
});
|
|
596
|
+
}), i.bindDidSpaces && (await Re(t?.user) || await new Promise((a) => {
|
|
597
|
+
i.bindDidSpaces === "full" ? U({
|
|
598
|
+
onSuccess() {
|
|
599
|
+
a();
|
|
600
|
+
}
|
|
601
|
+
}) : i.bindDidSpaces === "read" && we({
|
|
602
|
+
onSuccess() {
|
|
603
|
+
a();
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
})), n === "window" ? y.openPopup(e, o) : n === "popup" && y.open(e);
|
|
607
|
+
});
|
|
608
|
+
ae(() => {
|
|
609
|
+
const e = Number(t.unReadCount || 0);
|
|
610
|
+
de(e);
|
|
611
|
+
}, [t.unReadCount]);
|
|
612
|
+
const To = f(() => {
|
|
613
|
+
B.get("magicToken") && B.delete("magicToken"), B.toString() && window.history.replaceState({}, "", `${window.location.pathname}?${B.toString()}`);
|
|
614
|
+
}), Se = f((e) => new Promise((o, i) => {
|
|
615
|
+
y.open({
|
|
616
|
+
action: "login",
|
|
617
|
+
locale: b,
|
|
618
|
+
prefix: s.prefix,
|
|
619
|
+
useSocket: !1,
|
|
620
|
+
messages: {
|
|
621
|
+
title: b === "zh" ? "验证 MagicLink Token" : "Verify MagicLink Token"
|
|
622
|
+
},
|
|
623
|
+
magicToken: e,
|
|
624
|
+
onSuccess(...n) {
|
|
625
|
+
G(...n), To(), o();
|
|
626
|
+
},
|
|
627
|
+
onError(n) {
|
|
628
|
+
console.error(n), i(n);
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
})), Do = {
|
|
632
|
+
...t,
|
|
633
|
+
loading: s.autoConnect && !t.user || t.loading,
|
|
634
|
+
openDidConnect: yo,
|
|
635
|
+
login: te,
|
|
636
|
+
logout: ue,
|
|
637
|
+
switchDid: ne,
|
|
638
|
+
autoSwitchDid: ge,
|
|
639
|
+
refreshProfile: lo,
|
|
640
|
+
switchProfile: po,
|
|
641
|
+
switchPassport: fo,
|
|
642
|
+
connectToDidSpaceForImport: we,
|
|
643
|
+
connectToDidSpaceForFullAccess: U,
|
|
644
|
+
bindWallet: he,
|
|
645
|
+
refresh: A,
|
|
646
|
+
updateConnectedInfo: Z,
|
|
647
|
+
// federated relates
|
|
648
|
+
federatedMaster: Po,
|
|
649
|
+
// oauth relates
|
|
650
|
+
useOAuth: ci,
|
|
651
|
+
OAuthProvider: Oe,
|
|
652
|
+
OAuthConsumer: si,
|
|
653
|
+
OAuthContext: ni,
|
|
654
|
+
// passkey relates
|
|
655
|
+
usePasskey: di,
|
|
656
|
+
PasskeyProvider: _e,
|
|
657
|
+
PasskeyConsumer: li,
|
|
658
|
+
PasskeyContext: ai,
|
|
659
|
+
// user related
|
|
660
|
+
useDid: pi,
|
|
661
|
+
WrapDid: ui,
|
|
662
|
+
getUserSessions: me,
|
|
663
|
+
async loginUserSession(e) {
|
|
664
|
+
const o = await re(e);
|
|
665
|
+
Z(
|
|
666
|
+
{
|
|
667
|
+
connected_did: e.user.did,
|
|
668
|
+
connected_pk: e.user.pk,
|
|
669
|
+
connected_wallet_os: e.extra.walletOS,
|
|
670
|
+
connected_app: ee()
|
|
671
|
+
},
|
|
672
|
+
!0
|
|
673
|
+
), E({ ...o, encrypted: !1 }), await A({ showProgress: !0 }), await L(200), g.emit(w.LOGIN, o, x, C.current), O(C.current), await U();
|
|
674
|
+
},
|
|
675
|
+
unReadCount: Ve,
|
|
676
|
+
setUnReadCount: de,
|
|
677
|
+
verifyMagicToken: Se,
|
|
678
|
+
// 二次认证相关方法
|
|
679
|
+
withSecondaryAuth: no
|
|
680
|
+
}, C = Te(Do), Io = {
|
|
681
|
+
api: Ze,
|
|
682
|
+
events: g,
|
|
683
|
+
storage: Q,
|
|
684
|
+
connectApi: y,
|
|
685
|
+
session: C.current
|
|
686
|
+
}, vo = {
|
|
687
|
+
login: G,
|
|
688
|
+
"switch-profile": mo,
|
|
689
|
+
"switch-passport": se,
|
|
690
|
+
"bind-wallet": ho
|
|
691
|
+
};
|
|
692
|
+
ae(() => {
|
|
693
|
+
if (t.initialized) {
|
|
694
|
+
const e = !Xe;
|
|
695
|
+
if (g.emit("change", { user: be(t.user), isFirst: e }), t.user && globalThis.blocklet) {
|
|
696
|
+
const o = {
|
|
697
|
+
did: t.user.did,
|
|
698
|
+
host: window.location.host,
|
|
699
|
+
appPid: globalThis.blocklet.appPid,
|
|
700
|
+
visitorId: $(),
|
|
701
|
+
sourceAppPid: t.user.sourceAppPid,
|
|
702
|
+
fullName: t.user.fullName
|
|
703
|
+
};
|
|
704
|
+
u("bridge callArc: onChange", {
|
|
705
|
+
isFirst: e,
|
|
706
|
+
user: o
|
|
707
|
+
}), P.callArc("onChange", {
|
|
708
|
+
...o,
|
|
709
|
+
user: o,
|
|
710
|
+
isFirst: e
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}, [t.user, t.initialized, g]), ae(() => {
|
|
715
|
+
t.initialized && t.user && ge();
|
|
716
|
+
}, [t.initialized]), Vo(async () => {
|
|
717
|
+
const e = (c) => {
|
|
718
|
+
oi(c.encrypted) && (c.encrypted = !1), window.temporaryDIDConnectOnSuccess instanceof Function ? (u("bridgeOnLogin: temporaryDIDConnectOnSuccess", { result: c }), window.temporaryDIDConnectOnSuccess(c, (h) => h)) : (u("bridgeOnLogin: onLogin", { result: c }), G(c));
|
|
719
|
+
};
|
|
720
|
+
if (P.registerBlocklet("callLoginOAuth", (c) => {
|
|
721
|
+
u("bridge registerBlocklet: callLoginOAuth", c), y.loginOAuth({
|
|
722
|
+
...c,
|
|
723
|
+
onLogin: e
|
|
724
|
+
});
|
|
725
|
+
}), P.registerBlocklet("logout", ue), P.registerBlocklet("login", (c) => {
|
|
726
|
+
u("bridge registerBlocklet: login", c), e(c);
|
|
727
|
+
}), Fo(), !$()) {
|
|
728
|
+
if (T.arcSphere) {
|
|
729
|
+
u("bridge callArc: getVisitorId");
|
|
730
|
+
const c = await P.callArc("getVisitorId");
|
|
731
|
+
u("bridge callArc: getVisitorId result", { walletVisitorId: c }), Ae(c);
|
|
732
|
+
} else if (T.wallet) {
|
|
733
|
+
const c = await Ci();
|
|
734
|
+
Ae(c);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const i = Ro.get("connected_app"), n = ee();
|
|
738
|
+
if (r.autoDisconnect && i && n && i !== n) {
|
|
739
|
+
pe(), t.initialized = !0, s.autoConnect ? N() : V();
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const a = eo();
|
|
743
|
+
if (window?.self === window?.parent) {
|
|
744
|
+
let c = "web";
|
|
745
|
+
if (T.mobile.apple.device ? c = "ios" : T.mobile.android.device && (c = "android"), T.wallet && ki({ version: T.walletVersion, platform: c }) && !a)
|
|
746
|
+
try {
|
|
747
|
+
t.loading = !0;
|
|
748
|
+
const h = await yi();
|
|
749
|
+
if (h) {
|
|
750
|
+
await G({
|
|
751
|
+
sessionToken: h.sessionToken,
|
|
752
|
+
refreshToken: h.refreshToken,
|
|
753
|
+
visitorId: h.visitorId,
|
|
754
|
+
encrypted: !1
|
|
755
|
+
}), t.initialized = !0;
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
} finally {
|
|
759
|
+
t.loading = !1;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const d = B.get("magicToken");
|
|
763
|
+
if (d)
|
|
764
|
+
try {
|
|
765
|
+
t.initialized = !0, await Se(d);
|
|
766
|
+
} catch (c) {
|
|
767
|
+
console.error("verifyMagicToken failed", c);
|
|
768
|
+
}
|
|
769
|
+
if (a) {
|
|
770
|
+
await A({ showProgress: !0 }), t.initialized = !0, t.user && await U();
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (typeof window < "u") {
|
|
774
|
+
const c = new URL(window.location.href), h = c.searchParams.get("loginToken");
|
|
775
|
+
if (h) {
|
|
776
|
+
E({ loginToken: h, encrypted: !1 }), c.searchParams.delete("loginToken"), window.history.replaceState({}, window.title, c.href);
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (oo()) {
|
|
781
|
+
await Ye(!0), t.initialized = !0;
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
if (t.initialized = !0, s.autoConnect ? N() : V(), T.arcSphere && ![
|
|
785
|
+
// 不应该唤起自动登录的路由
|
|
786
|
+
z(F, "login"),
|
|
787
|
+
z(F, "connect"),
|
|
788
|
+
z(F, "lost-passport")
|
|
789
|
+
].includes(window.location.pathname) && !a)
|
|
790
|
+
try {
|
|
791
|
+
u("bridge callArc: autoLogin");
|
|
792
|
+
const c = await P.callArc("autoLogin");
|
|
793
|
+
u("bridgecallArc: autoLogin result", c), c && await G({
|
|
794
|
+
sessionToken: c.sessionToken,
|
|
795
|
+
refreshToken: c.refreshToken,
|
|
796
|
+
visitorId: c.visitorId,
|
|
797
|
+
encrypted: !1
|
|
798
|
+
});
|
|
799
|
+
} catch (c) {
|
|
800
|
+
Le.error("Failed to autoLogin ArcSphere", c);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
const xo = B.has("popup");
|
|
804
|
+
if (Co() && !t.initialized)
|
|
805
|
+
return /* @__PURE__ */ m(Ho, { children: xo ? null : /* @__PURE__ */ m(Mo, {}) });
|
|
806
|
+
const Pe = {
|
|
807
|
+
locale: b,
|
|
808
|
+
onSwitchPassport: ({ sessionToken: e, refreshToken: o }) => se({ sessionToken: e, refreshToken: o, encrypted: !1 }),
|
|
809
|
+
onUnbindOAuth: () => A(),
|
|
810
|
+
onBindOAuth: () => A(),
|
|
811
|
+
onAddPasskey: () => A(),
|
|
812
|
+
onRemovePasskey: () => A()
|
|
813
|
+
};
|
|
814
|
+
return /* @__PURE__ */ m(Li, { value: Io, children: /* @__PURE__ */ m(_e, { ...Pe, children: /* @__PURE__ */ j(Oe, { ...Pe, children: [
|
|
815
|
+
!t.open && typeof r.children == "function" ? r.children(t) : r.children,
|
|
816
|
+
ie,
|
|
817
|
+
qe,
|
|
818
|
+
wo,
|
|
819
|
+
k.rolling && /* @__PURE__ */ m(Ee, { callback: () => Je() }),
|
|
820
|
+
/* @__PURE__ */ m(Ee, { callback: Qe })
|
|
821
|
+
] }) }) });
|
|
822
|
+
}
|
|
823
|
+
le.propTypes = {
|
|
824
|
+
children: S.any.isRequired,
|
|
825
|
+
serviceHost: S.string,
|
|
826
|
+
action: S.string,
|
|
827
|
+
prefix: S.string,
|
|
828
|
+
appendAuthServicePrefix: S.bool,
|
|
829
|
+
locale: S.string,
|
|
830
|
+
timeout: S.number,
|
|
831
|
+
autoConnect: S.bool,
|
|
832
|
+
// should we open connect dialog when session not found
|
|
833
|
+
autoDisconnect: S.bool,
|
|
834
|
+
// should we auto disconnect on appId mismatch
|
|
835
|
+
useSocket: S.bool,
|
|
836
|
+
// should we auto disconnect on appId mismatch
|
|
837
|
+
extraParams: S.object,
|
|
838
|
+
options: S.object,
|
|
839
|
+
webWalletUrl: S.string,
|
|
840
|
+
protectedRoutes: S.arrayOf(S.string),
|
|
841
|
+
apiOptions: S.object,
|
|
842
|
+
lazyRefreshToken: S.bool
|
|
843
|
+
};
|
|
844
|
+
function Ge(D) {
|
|
845
|
+
return function(y) {
|
|
846
|
+
return /* @__PURE__ */ m(Ce, { children: /* @__PURE__ */ m(Ne, { children: (ie) => /* @__PURE__ */ m(D, { ...y, ...ie }) }) });
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
SessionProvider: (D) => /* @__PURE__ */ m(Ce, { children: /* @__PURE__ */ m(Ii, { children: /* @__PURE__ */ m(le, { ...D }) }) }),
|
|
851
|
+
SessionConsumer: Ne,
|
|
852
|
+
SessionContext: ze,
|
|
853
|
+
withSession: Ge
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
function Et({ storageEngine: q = "cookie" } = {}) {
|
|
857
|
+
const X = Fe, oe = He;
|
|
858
|
+
let k = null;
|
|
859
|
+
if (typeof window < "u" && (k = (globalThis.blocklet || {}).componentId), q === "cookie") {
|
|
860
|
+
let v = "/", O = 1;
|
|
861
|
+
if (typeof window < "u") {
|
|
862
|
+
const Q = window.env || {}, H = window.blocklet || {};
|
|
863
|
+
v = Q.groupPathPrefix || H.groupPrefix || H.prefix || "", v = v.replace(/\/+$/, ""), v = v || "/", H.serverVersion && (O = ri(window.blocklet?.settings?.session?.cacheTtl, 1 / 24));
|
|
864
|
+
}
|
|
865
|
+
return Me(
|
|
866
|
+
X,
|
|
867
|
+
"cookie",
|
|
868
|
+
{
|
|
869
|
+
path: v,
|
|
870
|
+
returnDomain: !1,
|
|
871
|
+
expireInDays: O
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
appendAuthServicePrefix: !0,
|
|
875
|
+
extraParams: { componentId: k },
|
|
876
|
+
refreshTokenStorageKey: oe
|
|
877
|
+
}
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
if (q === "localStorage")
|
|
881
|
+
return Me(X, "ls", {}, !0);
|
|
882
|
+
throw new Error("storageEngine must be cookie or localStorage");
|
|
883
|
+
}
|
|
884
|
+
export {
|
|
885
|
+
w as EVENTS,
|
|
886
|
+
ze as SessionContext,
|
|
887
|
+
ki as checkEnableAutoLogin,
|
|
888
|
+
Et as createAuthServiceSessionContext,
|
|
889
|
+
Me as default,
|
|
890
|
+
Re as didSpacesIsRequired,
|
|
891
|
+
Ci as getMobileVisitorId,
|
|
892
|
+
yi as login,
|
|
893
|
+
Rt as loginFederatedMaster,
|
|
894
|
+
Ut as mountFederatedIframe,
|
|
895
|
+
W as translations
|
|
896
|
+
};
|