@arcblock/did-connect-react 3.5.1 → 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 -133700
- 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/package.json.js +0 -7
- package/lib/types.d.ts +0 -355
- package/lib/utils.js +0 -225
package/lib/utils.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { Buffer as a } from "buffer";
|
|
2
|
-
import h from "tweetnacl-sealedbox-js";
|
|
3
|
-
import { isUrl as U, getCookieOptions as A, getVisitorId as E } from "@arcblock/ux/lib/Util";
|
|
4
|
-
import { getVisitorId as Ue, setVisitorId as Ae } from "@arcblock/ux/lib/Util";
|
|
5
|
-
import c from "js-cookie";
|
|
6
|
-
import l from "lodash/isNil";
|
|
7
|
-
import T from "lodash/isString";
|
|
8
|
-
import m from "lodash/isUndefined";
|
|
9
|
-
import { createAxios as P, getBlockletSDK as x } from "@blocklet/js-sdk";
|
|
10
|
-
import { withQuery as L } from "ufo";
|
|
11
|
-
import { isValid as w, isFromPublicKey as S } from "@arcblock/did";
|
|
12
|
-
import { getSafeUrl as C } from "@arcblock/ux/lib/Util/security";
|
|
13
|
-
import { createDebug as u, createLogger as I } from "@arcblock/ux/lib/Util/logger";
|
|
14
|
-
import N from "./package.json.js";
|
|
15
|
-
import { DID_CONNECT_URL_PARAMS_NAME as f, DEFAULT_WINDOW_TIMEOUT as D } from "./constant.js";
|
|
16
|
-
import { NotOpenError as W } from "./error.js";
|
|
17
|
-
export * from "@arcblock/ux/lib/Util/wallet";
|
|
18
|
-
const { version: O } = N, re = u("did-connect"), oe = u("did-connect:tmp"), te = u("did-connect:tmp-interval"), ne = I("did-connect");
|
|
19
|
-
function b(e) {
|
|
20
|
-
return (e + "===".slice((e.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
|
|
21
|
-
}
|
|
22
|
-
function _(e) {
|
|
23
|
-
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
24
|
-
}
|
|
25
|
-
const se = (e) => _(window.btoa(e)), ie = (e) => window.atob(b(e)), ae = (e) => {
|
|
26
|
-
const o = new URL(e), r = decodeURIComponent(o.searchParams.get("url"));
|
|
27
|
-
return new URL(r).searchParams.get("_t_");
|
|
28
|
-
}, R = (e, o) => {
|
|
29
|
-
let r = o?.publisher;
|
|
30
|
-
if (!r) {
|
|
31
|
-
if (e?.agentDid)
|
|
32
|
-
return e.agentDid;
|
|
33
|
-
r = e?.publisher;
|
|
34
|
-
}
|
|
35
|
-
return r ? r.replace("did:abt:", "") : globalThis.blocklet?.appPid || globalThis.blocklet?.appId || globalThis.env?.appId || "";
|
|
36
|
-
}, z = (e) => {
|
|
37
|
-
const o = {
|
|
38
|
-
connected_did: e.did || "",
|
|
39
|
-
connected_pk: e.pk || "",
|
|
40
|
-
connected_app: R(e.appInfo, e.memberAppInfo)
|
|
41
|
-
};
|
|
42
|
-
return e?.connectedWallet?.os && (o.connected_wallet_os = e.connectedWallet.os), o;
|
|
43
|
-
}, ce = (e, o = !1) => {
|
|
44
|
-
if (!e) return;
|
|
45
|
-
o || (e = z(e));
|
|
46
|
-
const r = A({
|
|
47
|
-
expireInDays: 7,
|
|
48
|
-
returnDomain: !1
|
|
49
|
-
});
|
|
50
|
-
!l(e.connected_did) && !l(e.connected_pk) && w(e.connected_did) && S(e.connected_did, e.connected_pk) && (c.set("connected_did", e.connected_did, r), c.set("connected_pk", e.connected_pk, r)), !l(e.connected_app) && w(e.connected_app) && c.set("connected_app", e.connected_app, r), e.connected_wallet_os && c.set("connected_wallet_os", e.connected_wallet_os, r);
|
|
51
|
-
}, pe = (e) => _(a.from(e).toString("base64")), d = (e) => Uint8Array.from(a.from(b(e), "base64")), le = (e, o, r) => {
|
|
52
|
-
const t = h.open(
|
|
53
|
-
Uint8Array.from(a.from(e, "base64")),
|
|
54
|
-
d(o),
|
|
55
|
-
d(r)
|
|
56
|
-
);
|
|
57
|
-
return JSON.parse(a.from(t).toString("utf8"));
|
|
58
|
-
}, de = (e, o) => a.from(h.seal(Uint8Array.from(a.from(e)), d(o))).toString("base64"), ue = (e, o = "_t_") => {
|
|
59
|
-
const r = new URL(e), t = {
|
|
60
|
-
baseUrl: r.origin,
|
|
61
|
-
prefix: r.pathname.replace(/\/auth$/, ""),
|
|
62
|
-
token: r.searchParams.get(o) || ""
|
|
63
|
-
};
|
|
64
|
-
if (!t.baseUrl)
|
|
65
|
-
throw new Error("Invalid next workflow: origin empty");
|
|
66
|
-
if (!t.token)
|
|
67
|
-
throw new Error("Invalid next workflow: token not found");
|
|
68
|
-
return t;
|
|
69
|
-
}, g = (e, o) => {
|
|
70
|
-
let r = e.message;
|
|
71
|
-
const { response: t } = e;
|
|
72
|
-
return t && (r = t.data?.error || t.data?.message || t.data || o, r = typeof r == "object" ? o : r), r;
|
|
73
|
-
}, me = (e, o, r) => {
|
|
74
|
-
if (!e)
|
|
75
|
-
return e;
|
|
76
|
-
if (!e.name)
|
|
77
|
-
return g(e, o);
|
|
78
|
-
switch (e.name) {
|
|
79
|
-
case "NotAllowedError":
|
|
80
|
-
return r ? r("webauthn.error.canceled") : "Authentication was canceled";
|
|
81
|
-
case "SecurityError":
|
|
82
|
-
return r ? r("webauthn.error.security") : "A security error occurred during authentication";
|
|
83
|
-
case "NotSupportedError":
|
|
84
|
-
return r ? r("webauthn.error.notSupported") : "This browser does not support passkey authentication";
|
|
85
|
-
case "AbortError":
|
|
86
|
-
return r ? r("webauthn.error.aborted") : "Authentication was aborted";
|
|
87
|
-
default:
|
|
88
|
-
return console.warn("Unhandled WebAuthn error type:", e.name), g(e, o);
|
|
89
|
-
}
|
|
90
|
-
}, M = (e) => {
|
|
91
|
-
const o = {}, r = U(e) ? e : window.location.href;
|
|
92
|
-
if (r) {
|
|
93
|
-
const { hostname: t, protocol: n, port: s } = new URL(r);
|
|
94
|
-
o["x-real-hostname"] = t, o["x-real-port"] = s, o["x-real-protocol"] = n.endsWith(":") ? n.substring(0, n.length - 1) : n;
|
|
95
|
-
}
|
|
96
|
-
return o;
|
|
97
|
-
}, we = (e = {}, { lazy: o = !1, lazyTime: r = 300 } = {}) => {
|
|
98
|
-
const t = {
|
|
99
|
-
...M(e.baseURL),
|
|
100
|
-
...e.headers,
|
|
101
|
-
"x-did-connect-version": O
|
|
102
|
-
}, n = P(
|
|
103
|
-
{
|
|
104
|
-
...e,
|
|
105
|
-
headers: t
|
|
106
|
-
},
|
|
107
|
-
{ lazy: o, lazyTime: r }
|
|
108
|
-
);
|
|
109
|
-
return n.interceptors.request.use((s) => {
|
|
110
|
-
const i = E();
|
|
111
|
-
return i && (s.headers["x-blocklet-visitor-id"] = i), s;
|
|
112
|
-
}), n;
|
|
113
|
-
}, fe = (e = 0) => new Promise((o) => {
|
|
114
|
-
setTimeout(() => {
|
|
115
|
-
o();
|
|
116
|
-
}, e);
|
|
117
|
-
});
|
|
118
|
-
function ge() {
|
|
119
|
-
if (typeof window > "u")
|
|
120
|
-
return null;
|
|
121
|
-
const e = window.navigator.languages && window.navigator.languages[0] || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage || window.navigator.systemLanguage || null;
|
|
122
|
-
return {
|
|
123
|
-
"zh-CN": "zh",
|
|
124
|
-
"zh-TW": "zh",
|
|
125
|
-
zh: "zh",
|
|
126
|
-
en: "en"
|
|
127
|
-
}[e] || "en";
|
|
128
|
-
}
|
|
129
|
-
function he(e, o) {
|
|
130
|
-
return [void 0, null, ""].includes(e) ? o : e / 86400;
|
|
131
|
-
}
|
|
132
|
-
async function be() {
|
|
133
|
-
const e = window.location.href;
|
|
134
|
-
try {
|
|
135
|
-
const o = new URL(e), r = o.searchParams.get(f);
|
|
136
|
-
if (r) {
|
|
137
|
-
o.searchParams.delete(f);
|
|
138
|
-
const t = JSON.parse(a.from(r, "base64").toString("utf-8"));
|
|
139
|
-
if (T(t.forceConnected) && m(t.sourceAppPid)) {
|
|
140
|
-
const s = await x().user.getUserPublicInfo({ did: t.forceConnected });
|
|
141
|
-
m(s?.sourceAppPid) || (t.sourceAppPid = s.sourceAppPid);
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
params: t,
|
|
145
|
-
url: o.href
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
} catch {
|
|
149
|
-
console.warn("Failed to decode did-connect url params");
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
params: null,
|
|
153
|
-
url: e
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
const _e = (e, { width: o = 680, height: r = 720, name: t = "did-connect:popup", offsetX: n = 0, offsetY: s = 0 } = {}) => {
|
|
157
|
-
const i = C(e, { allowDomains: null }), v = window.screenX + (window.innerWidth - o) / 2 + n, k = window.screenY + (window.innerHeight - r) / 2 + s, y = [
|
|
158
|
-
`left=${v}`,
|
|
159
|
-
`top=${k}`,
|
|
160
|
-
`width=${o}`,
|
|
161
|
-
`height=${r}`,
|
|
162
|
-
"resizable=no",
|
|
163
|
-
// not working
|
|
164
|
-
"scrollbars=yes",
|
|
165
|
-
"status=yes",
|
|
166
|
-
"popup=yes"
|
|
167
|
-
], p = window.open("", t, y.join(","));
|
|
168
|
-
if (p === null)
|
|
169
|
-
throw new W();
|
|
170
|
-
return p.location.href = L(i, {
|
|
171
|
-
// NOTICE: 携带当前页面的 origin,用于在 popup 中通过该参数判断是否可以发送 postMessage,即使该参数被伪造,最终也只有该域名能接收到消息,所以没有关系
|
|
172
|
-
opener: window.location.origin
|
|
173
|
-
}), p;
|
|
174
|
-
}, ve = (e) => new Promise((o, r) => {
|
|
175
|
-
let t, n;
|
|
176
|
-
const s = ({ data: i }) => {
|
|
177
|
-
if (i && i.type === "authorization_response") {
|
|
178
|
-
if (i?.error) {
|
|
179
|
-
console.error(i.error);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
setTimeout(() => {
|
|
183
|
-
e.popup?.close(), clearTimeout(n), clearInterval(t), window.removeEventListener("message", s, !1);
|
|
184
|
-
}, e.closeTimeout || 0), o(i);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
n = setTimeout(
|
|
188
|
-
() => {
|
|
189
|
-
clearInterval(t), r(new Error("Timeout")), window.removeEventListener("message", s, !1);
|
|
190
|
-
},
|
|
191
|
-
(e.timeoutInSeconds || D) * 1e3
|
|
192
|
-
), t = setInterval(() => {
|
|
193
|
-
e.popup?.closed && (clearInterval(t), clearTimeout(n), window.removeEventListener("message", s, !1), r(new Error("Popup closed")));
|
|
194
|
-
}, 1e3), window.addEventListener("message", s);
|
|
195
|
-
});
|
|
196
|
-
export {
|
|
197
|
-
we as createAxios,
|
|
198
|
-
re as debug,
|
|
199
|
-
oe as debugTmp,
|
|
200
|
-
te as debugTmpInterval,
|
|
201
|
-
ie as decodeConnectUrl,
|
|
202
|
-
d as decodeKey,
|
|
203
|
-
be as decodeUrlParams,
|
|
204
|
-
le as decrypt,
|
|
205
|
-
se as encodeConnectUrl,
|
|
206
|
-
pe as encodeKey,
|
|
207
|
-
de as encrypt,
|
|
208
|
-
he as formatCacheTtl,
|
|
209
|
-
g as getApiErrorMessage,
|
|
210
|
-
R as getAppId,
|
|
211
|
-
ge as getBrowserLang,
|
|
212
|
-
z as getConnectedInfo,
|
|
213
|
-
M as getExtraHeaders,
|
|
214
|
-
Ue as getVisitorId,
|
|
215
|
-
me as getWebAuthnErrorMessage,
|
|
216
|
-
ne as logger,
|
|
217
|
-
_e as openPopup,
|
|
218
|
-
ue as parseNextWorkflow,
|
|
219
|
-
ae as parseTokenFromConnectUrl,
|
|
220
|
-
ve as runPopup,
|
|
221
|
-
Ae as setVisitorId,
|
|
222
|
-
fe as sleep,
|
|
223
|
-
ce as updateConnectedInfo,
|
|
224
|
-
O as version
|
|
225
|
-
};
|