@arcblock/did-connect-react 3.3.9 → 3.3.10
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/lib/Connect/hooks/token.js +128 -136
- package/lib/index.js +47 -46
- package/lib/package.json.js +1 -1
- package/lib/utils.js +97 -88
- package/package.json +5 -5
- package/src/Connect/hooks/token.js +1 -13
- package/src/utils.js +17 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef as I, useEffect as
|
|
2
|
-
import
|
|
1
|
+
import { useRef as I, useEffect as C } from "react";
|
|
2
|
+
import T from "lodash/get";
|
|
3
3
|
import ue from "js-cookie";
|
|
4
4
|
import B from "lodash/omitBy";
|
|
5
5
|
import M from "lodash/isNil";
|
|
@@ -9,71 +9,63 @@ import { useReactive as H, useCreation as pe, useMemoizedFn as E } from "ahooks"
|
|
|
9
9
|
import ke from "@arcblock/react-hooks/lib/useInterval";
|
|
10
10
|
import me from "@arcblock/react-hooks/lib/useBrowser";
|
|
11
11
|
import { getVisitorId as he, stringifyQuery as $, isUrl as ge } from "@arcblock/ux/lib/Util";
|
|
12
|
-
import { WsClient as
|
|
13
|
-
import { sleep as q, getConnectedInfo as
|
|
12
|
+
import { WsClient as be } from "@arcblock/ws";
|
|
13
|
+
import { sleep as q, getExtraHeaders as x, getConnectedInfo as we, updateConnectedInfo as Ce, parseNextWorkflow as Q, createAxios as z, decodeConnectUrl as Se, parseTokenFromConnectUrl as Ie } from "../../utils.js";
|
|
14
14
|
import V from "../assets/locale.js";
|
|
15
|
-
import
|
|
16
|
-
import
|
|
15
|
+
import $e from "./security.js";
|
|
16
|
+
import xe from "./page-show.js";
|
|
17
17
|
import { RELAY_SOCKET_PREFIX as G } from "../../constant.js";
|
|
18
18
|
function ve(o) {
|
|
19
|
-
const
|
|
20
|
-
return new URL(
|
|
19
|
+
const l = o || window.location.href;
|
|
20
|
+
return new URL(l).host;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return a;
|
|
29
|
-
}
|
|
30
|
-
const R = {};
|
|
31
|
-
function Ue({ action: o, prefix: a, checkFn: d, extraParams: w, baseUrl: i }) {
|
|
32
|
-
const p = `${a}/token?${$(w)}`;
|
|
33
|
-
return R[p] || (R[p] = async function() {
|
|
34
|
-
const k = +/* @__PURE__ */ new Date(), h = await d(p, { headers: v(i) }), g = +/* @__PURE__ */ new Date();
|
|
35
|
-
if (g - k < 500 && await q(500 - (g - k)), h?.data?.token)
|
|
22
|
+
const P = {};
|
|
23
|
+
function Ue({ action: o, prefix: l, checkFn: k, extraParams: v, baseUrl: m }) {
|
|
24
|
+
const d = `${l}/token?${$(v)}`;
|
|
25
|
+
return P[d] || (P[d] = async function() {
|
|
26
|
+
const f = +/* @__PURE__ */ new Date(), h = await k(d, { headers: x(m) }), g = +/* @__PURE__ */ new Date();
|
|
27
|
+
if (g - f < 500 && await q(500 - (g - f)), h?.data?.token)
|
|
36
28
|
return h.data;
|
|
37
29
|
if (h?.data?.error)
|
|
38
30
|
throw new Error(h.data.error);
|
|
39
|
-
const U = ge(
|
|
31
|
+
const U = ge(l) ? l : `${m}${l}`;
|
|
40
32
|
throw new Error(`Error generating ${o} QR Code from: ${U}`);
|
|
41
|
-
}),
|
|
33
|
+
}), P[d];
|
|
42
34
|
}
|
|
43
35
|
const Ae = () => {
|
|
44
36
|
try {
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
37
|
+
const l = new URL(window.location.href).searchParams.get("__connect_url__");
|
|
38
|
+
if (!l)
|
|
47
39
|
return null;
|
|
48
|
-
const
|
|
40
|
+
const k = Se(l);
|
|
49
41
|
return {
|
|
50
|
-
token:
|
|
51
|
-
url:
|
|
42
|
+
token: Ie(k),
|
|
43
|
+
url: k
|
|
52
44
|
};
|
|
53
45
|
} catch (o) {
|
|
54
46
|
return {
|
|
55
47
|
error: o
|
|
56
48
|
};
|
|
57
49
|
}
|
|
58
|
-
}, J = () =>
|
|
50
|
+
}, J = () => T(globalThis, "blocklet.appPid") || T(globalThis, "blocklet.appId") || T(globalThis, "env.appId") || "", ye = () => (T(globalThis, "env.apiPrefix") || "/").replace(/\/$/, "").replace(G, ""), R = (o) => `relay:${J()}:${o}`, Ee = () => window.location.protocol === "https:" ? "wss:" : "ws:", X = (o) => !o || new URL(o).origin === window.location.origin, Y = (o) => ["succeed", "error", "timeout", "busy"].includes(o);
|
|
59
51
|
function Xe({
|
|
60
52
|
action: o,
|
|
61
|
-
checkFn:
|
|
62
|
-
checkInterval:
|
|
63
|
-
checkTimeout:
|
|
64
|
-
extraParams:
|
|
65
|
-
locale:
|
|
53
|
+
checkFn: l,
|
|
54
|
+
checkInterval: k,
|
|
55
|
+
checkTimeout: v,
|
|
56
|
+
extraParams: m,
|
|
57
|
+
locale: d,
|
|
66
58
|
prefix: _,
|
|
67
|
-
tokenKey:
|
|
59
|
+
tokenKey: f,
|
|
68
60
|
encKey: h,
|
|
69
61
|
onError: g,
|
|
70
62
|
onSuccess: U,
|
|
71
63
|
baseUrl: Z,
|
|
72
64
|
autoConnect: K = !0,
|
|
73
65
|
forceConnected: ee = !0,
|
|
74
|
-
saveConnect:
|
|
66
|
+
saveConnect: re = !0,
|
|
75
67
|
// FIXME: @zhanghan 将来需要设置为默认 false,仅在需要的时候进行保存 login, switch/role/profile
|
|
76
|
-
useSocket:
|
|
68
|
+
useSocket: te = !0,
|
|
77
69
|
provider: ne = "wallet"
|
|
78
70
|
}) {
|
|
79
71
|
const e = H({
|
|
@@ -94,41 +86,41 @@ function Xe({
|
|
|
94
86
|
nextWorkflow: "",
|
|
95
87
|
baseUrl: Z,
|
|
96
88
|
prefix: `${_}/${o}`,
|
|
97
|
-
extraParams: B(
|
|
98
|
-
checkFn:
|
|
89
|
+
extraParams: B(m, M),
|
|
90
|
+
checkFn: l,
|
|
99
91
|
results: {},
|
|
100
92
|
action: o,
|
|
101
93
|
provider: ne,
|
|
102
94
|
reset() {
|
|
103
95
|
this.error = "", this.status = "created";
|
|
104
96
|
}
|
|
105
|
-
}), F = I(null),
|
|
97
|
+
}), F = I(null), S = V[d] || V.en, u = pe(() => Ae(), []), oe = Math.ceil(v / k), c = H({
|
|
106
98
|
onSuccessCalled: !1,
|
|
107
99
|
cancelWhenScannedCounter: 0,
|
|
108
100
|
isSocketAvailable: !1
|
|
109
|
-
}), { encryptKey: se, decrypt: A } =
|
|
101
|
+
}), { encryptKey: se, decrypt: A } = $e(), D = me(), O = he(), a = I(null), p = I(null), b = {
|
|
110
102
|
...e.extraParams,
|
|
111
|
-
locale:
|
|
112
|
-
[
|
|
103
|
+
locale: d,
|
|
104
|
+
[f]: e.token || u?.token,
|
|
113
105
|
provider: e.provider
|
|
114
106
|
}, L = async () => {
|
|
115
|
-
if (!(
|
|
107
|
+
if (!(u?.token && u?.token === e.token)) {
|
|
116
108
|
try {
|
|
117
|
-
b[
|
|
118
|
-
headers:
|
|
109
|
+
b[f] && e.status === "created" && await e.checkFn(`${e.prefix}/timeout?${$(b)}`, {
|
|
110
|
+
headers: x(e.baseUrl)
|
|
119
111
|
});
|
|
120
112
|
} catch {
|
|
121
113
|
}
|
|
122
114
|
try {
|
|
123
|
-
e.token &&
|
|
115
|
+
e.token && p.current && (await a.current.unsubscribe(R(e.token)), p.current = null);
|
|
124
116
|
} catch {
|
|
125
117
|
}
|
|
126
118
|
}
|
|
127
|
-
}, ae = E((...
|
|
128
|
-
const
|
|
119
|
+
}, ae = E((...t) => {
|
|
120
|
+
const r = {
|
|
129
121
|
[h]: se,
|
|
130
122
|
...e.extraParams,
|
|
131
|
-
locale:
|
|
123
|
+
locale: d,
|
|
132
124
|
forceConnected: ee,
|
|
133
125
|
// - autoConnect 请求参数用于控制服务端是否给钱包应用发送自动连接通知
|
|
134
126
|
// - 使用 connect 组件时明确传入了 autoConnect = false, 则 autoConnect 请求参数 为 false
|
|
@@ -136,97 +128,97 @@ function Xe({
|
|
|
136
128
|
// (避免 "无限自动连接问题")
|
|
137
129
|
// - 如果上次连接设备 (connected_wallet_os) 不是 ios/android, 则禁用自动连接
|
|
138
130
|
autoConnect: K && // 如果是 wallet webview 环境, 不发送通知, 避免 wallet 连续弹出 auth 窗口 2 次 (#341)
|
|
139
|
-
!(D.wallet || D.arcSphere) && !
|
|
131
|
+
!(D.wallet || D.arcSphere) && !c.cancelWhenScannedCounter && ["ios", "android"].includes(ue.get("connected_wallet_os")),
|
|
140
132
|
provider: e.provider
|
|
141
133
|
};
|
|
142
|
-
O && (
|
|
134
|
+
O && (r.visitorId = O);
|
|
143
135
|
const n = fe(F.current || {}, ["sourceAppPid", "verbose"]);
|
|
144
136
|
return Object.keys(n).forEach((s) => {
|
|
145
|
-
(!
|
|
146
|
-
}),
|
|
137
|
+
(!r[s] || s === h && n[s]) && (r[s] = n[s]);
|
|
138
|
+
}), u?.token && !r.sourceToken && (r.sourceToken = u?.token), Ue({
|
|
147
139
|
action: o,
|
|
148
140
|
prefix: e.prefix,
|
|
149
141
|
baseUrl: e.baseUrl,
|
|
150
142
|
checkFn: e.checkFn,
|
|
151
|
-
extraParams:
|
|
152
|
-
})(...
|
|
153
|
-
}), y = E(async (
|
|
154
|
-
|
|
143
|
+
extraParams: r
|
|
144
|
+
})(...t);
|
|
145
|
+
}), y = E(async (t = !0) => {
|
|
146
|
+
t && L();
|
|
155
147
|
try {
|
|
156
|
-
e.loading = !0, e.token = "", e.url = "", e.store = null, e.extraParams = B(
|
|
157
|
-
const
|
|
158
|
-
e.loading = !1, e.token =
|
|
159
|
-
} catch (
|
|
160
|
-
e.loading = !1, e.status = "error", e.error = `${
|
|
148
|
+
e.loading = !0, e.token = "", e.url = "", e.store = null, e.extraParams = B(m, M), await q();
|
|
149
|
+
const r = await ae(), n = r.extra || {};
|
|
150
|
+
e.loading = !1, e.token = r.token, e.url = r.url, e.status = "created", e.error = "", e.checkCount = 0, e.appInfo = r.appInfo, e.memberAppInfo = r.memberAppInfo, e.connectedDid = n.connectedDid, e.saveConnect = n.saveConnect;
|
|
151
|
+
} catch (r) {
|
|
152
|
+
e.loading = !1, e.status = "error", e.error = `${S.generateError}: ${r.message}`;
|
|
161
153
|
}
|
|
162
154
|
}), ce = E(() => {
|
|
163
|
-
|
|
155
|
+
c.cancelWhenScannedCounter++;
|
|
164
156
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}, [
|
|
157
|
+
C(() => {
|
|
158
|
+
c.cancelWhenScannedCounter > 0 && (m.nw ? g(new Error(S.retryForbidden)) : y());
|
|
159
|
+
}, [c.cancelWhenScannedCounter]), C(() => (!(/^((?!chrome|android).)*safari/i.test(globalThis.navigator.userAgent) || Object.hasOwn(globalThis?.blocklet || {}, "DID_CONNECT_DISABLE_SOCKET")) && te && X(e.baseUrl) && J() ? (!a.current || a.current.isConnected() === !1 || a.current.baseUrl !== e.baseUrl) && (a.current = new be(
|
|
168
160
|
`${Ee()}//${ve(e.baseUrl)}${ye()}${G}/relay`,
|
|
169
161
|
{
|
|
170
162
|
longpollerTimeout: 5e3,
|
|
171
163
|
// connection timeout
|
|
172
164
|
heartbeatIntervalMs: 30 * 1e3
|
|
173
165
|
}
|
|
174
|
-
),
|
|
175
|
-
|
|
176
|
-
}),
|
|
177
|
-
|
|
166
|
+
), a.current.baseUrl = e.baseUrl, a.current.onOpen(() => {
|
|
167
|
+
c.isSocketAvailable = !0;
|
|
168
|
+
}), a.current.connect()) : c.isSocketAvailable && (c.isSocketAvailable = !1), () => {
|
|
169
|
+
a.current && (a.current.disconnect(), a.current = null);
|
|
178
170
|
}), [e.baseUrl]);
|
|
179
|
-
const ie = () => !e.token || e.loading || Y(e.status) ? null :
|
|
180
|
-
|
|
171
|
+
const ie = () => !e.token || e.loading || Y(e.status) ? null : k, j = I(null);
|
|
172
|
+
C(() => {
|
|
181
173
|
j.current = { state: e, params: b };
|
|
182
|
-
}),
|
|
183
|
-
const { state:
|
|
184
|
-
|
|
185
|
-
headers:
|
|
174
|
+
}), C(() => () => {
|
|
175
|
+
const { state: t, params: r } = j.current;
|
|
176
|
+
t.status === "created" && r[f] && t.checkFn(`${t.prefix}/timeout?${$(r)}`, {
|
|
177
|
+
headers: x(t.baseUrl)
|
|
186
178
|
});
|
|
187
179
|
}, []);
|
|
188
|
-
const
|
|
189
|
-
if ((e.checking || document.hidden) && !
|
|
180
|
+
const w = E(async (t = !1) => {
|
|
181
|
+
if ((e.checking || document.hidden) && !t || (e.status === "created" && e.checkCount++, c.isSocketAvailable && !t))
|
|
190
182
|
return null;
|
|
191
183
|
try {
|
|
192
184
|
e.checking = !0;
|
|
193
|
-
const
|
|
194
|
-
headers:
|
|
195
|
-
}), { status: n, error:
|
|
196
|
-
if (e.store =
|
|
197
|
-
const N = new Error(
|
|
198
|
-
throw N.response =
|
|
185
|
+
const r = await e.checkFn(`${e.prefix}/status?${$(b)}`, {
|
|
186
|
+
headers: x(e.baseUrl)
|
|
187
|
+
}), { status: n, error: i, mfaCode: s = 0 } = r.data;
|
|
188
|
+
if (e.store = r.data, e.mfaCode = s, e.checking = !1, e.status === "scanned" && n === "created" || (e.status = n), n === "error" && i) {
|
|
189
|
+
const N = new Error(i);
|
|
190
|
+
throw N.response = r, N;
|
|
199
191
|
}
|
|
200
|
-
return
|
|
201
|
-
} catch (
|
|
202
|
-
const { response: n } =
|
|
192
|
+
return r.data;
|
|
193
|
+
} catch (r) {
|
|
194
|
+
const { response: n } = r;
|
|
203
195
|
if (n?.status) {
|
|
204
|
-
b[
|
|
205
|
-
headers:
|
|
196
|
+
b[f] && e.checkFn(`${e.prefix}/timeout?${$(b)}`, {
|
|
197
|
+
headers: x(e.baseUrl)
|
|
206
198
|
});
|
|
207
|
-
const
|
|
208
|
-
s.code = n.status, e.status = "error", e.checking = !1, e.error =
|
|
199
|
+
const i = n?.data?.error ? n.data.error : r.message, s = new Error(i);
|
|
200
|
+
s.code = n.status, e.status = "error", e.checking = !1, e.error = i, g(s, e?.store, A);
|
|
209
201
|
} else
|
|
210
|
-
e.status = "error", e.checking = !1, e.error =
|
|
202
|
+
e.status = "error", e.checking = !1, e.error = S.generateError;
|
|
211
203
|
}
|
|
212
204
|
return null;
|
|
213
205
|
}), le = async () => {
|
|
214
206
|
try {
|
|
215
|
-
if (
|
|
216
|
-
throw
|
|
217
|
-
e.loading = !0, e.token =
|
|
218
|
-
let
|
|
219
|
-
if ((["scanned"].includes(
|
|
220
|
-
throw new Error(`${
|
|
221
|
-
} catch (
|
|
222
|
-
e.status = "error", e.error =
|
|
207
|
+
if (u.error)
|
|
208
|
+
throw u.error;
|
|
209
|
+
e.loading = !0, e.token = u.token, e.url = u.url, e.inExistingSession = !0;
|
|
210
|
+
let t = await w();
|
|
211
|
+
if ((["scanned"].includes(t?.status) || t?.sourceToken === u?.token) && (await y(!1), t = await w()), F.current = t?.extraParams || null, t?.status && !["created"].includes(t?.status))
|
|
212
|
+
throw new Error(`${S.invalidSessionStatus} [${t.status}]`);
|
|
213
|
+
} catch (t) {
|
|
214
|
+
e.status = "error", e.error = t.message, g(t, e?.store, A);
|
|
223
215
|
} finally {
|
|
224
216
|
e.loading = !1;
|
|
225
217
|
}
|
|
226
218
|
};
|
|
227
|
-
|
|
219
|
+
C(() => {
|
|
228
220
|
if (!e.token && !e.store && !e.loading && !e.error)
|
|
229
|
-
if (
|
|
221
|
+
if (u)
|
|
230
222
|
le();
|
|
231
223
|
else {
|
|
232
224
|
y(!1);
|
|
@@ -236,67 +228,67 @@ function Xe({
|
|
|
236
228
|
e.status = "timeout", L();
|
|
237
229
|
return;
|
|
238
230
|
}
|
|
239
|
-
if (e.status === "succeed" && !
|
|
240
|
-
const
|
|
231
|
+
if (e.status === "succeed" && !c.onSuccessCalled) {
|
|
232
|
+
const t = we({
|
|
241
233
|
...e.store,
|
|
242
234
|
appInfo: e.appInfo,
|
|
243
235
|
memberAppInfo: e.memberAppInfo
|
|
244
236
|
});
|
|
245
|
-
if (X(e.baseUrl) &&
|
|
246
|
-
const { nextWorkflow:
|
|
247
|
-
if (
|
|
237
|
+
if (X(e.baseUrl) && re && e.saveConnect && e.store.did && Ce(t, !0), e.store) {
|
|
238
|
+
const { nextWorkflow: r } = e.store;
|
|
239
|
+
if (r)
|
|
248
240
|
try {
|
|
249
|
-
const n = Q(
|
|
250
|
-
e.nextWorkflow = n?.nextWorkflow ||
|
|
241
|
+
const n = Q(r, f);
|
|
242
|
+
e.nextWorkflow = n?.nextWorkflow || r, Object.assign(e, n), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, e.checkCount = 0, e.status = "scanned", e.results = {
|
|
251
243
|
...e.results,
|
|
252
244
|
[e.token]: e.store
|
|
253
|
-
}, e.checkFn = z({ baseURL: n.baseUrl, timeout: 8e3 }).get,
|
|
245
|
+
}, e.checkFn = z({ baseURL: n.baseUrl, timeout: 8e3 }).get, w();
|
|
254
246
|
} catch (n) {
|
|
255
|
-
console.error(`Invalid nextWorkflow: ${
|
|
247
|
+
console.error(`Invalid nextWorkflow: ${r}`, n), e.status = "error", e.error = `Invalid nextWorkflow: ${r}: ${n.message}`;
|
|
256
248
|
}
|
|
257
249
|
else if (e.nextWorkflow && (e.nextWorkflow = "", e.url = ""), typeof U == "function") {
|
|
258
250
|
const n = Object.values({ ...e.results, [e.token]: e.store });
|
|
259
|
-
|
|
260
|
-
const
|
|
251
|
+
c.onSuccessCalled = !0;
|
|
252
|
+
const i = n.length > 1 ? n : n[0], s = de(i);
|
|
261
253
|
U(s, A, {
|
|
262
|
-
sourceAppPid:
|
|
263
|
-
...
|
|
254
|
+
sourceAppPid: m?.sourceAppPid,
|
|
255
|
+
...t
|
|
264
256
|
});
|
|
265
257
|
}
|
|
266
258
|
}
|
|
267
259
|
return;
|
|
268
260
|
}
|
|
269
261
|
if (e.store?.nextWorkflow) {
|
|
270
|
-
const { nextWorkflow:
|
|
262
|
+
const { nextWorkflow: t } = e.store;
|
|
271
263
|
try {
|
|
272
|
-
const
|
|
273
|
-
e.nextWorkflow =
|
|
264
|
+
const r = Q(t, f);
|
|
265
|
+
e.nextWorkflow = r?.nextWorkflow || t, Object.assign(e, r), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, e.checkCount = 0, e.status = "scanned", e.results = {
|
|
274
266
|
...e.results,
|
|
275
267
|
[e.token]: e.store
|
|
276
|
-
}, e.checkFn = z({ baseURL:
|
|
277
|
-
} catch (
|
|
278
|
-
console.error(`Invalid nextWorkflow: ${
|
|
268
|
+
}, e.checkFn = z({ baseURL: r.baseUrl, timeout: 8e3 }).get, w();
|
|
269
|
+
} catch (r) {
|
|
270
|
+
console.error(`Invalid nextWorkflow: ${t}`, r), e.status = "error", e.error = `Invalid nextWorkflow: ${t}: ${r.message}`;
|
|
279
271
|
}
|
|
280
272
|
}
|
|
281
273
|
});
|
|
282
|
-
const
|
|
283
|
-
return
|
|
284
|
-
if (e.token &&
|
|
285
|
-
let
|
|
286
|
-
|
|
287
|
-
const n = +new Date(
|
|
288
|
-
if (n <=
|
|
289
|
-
console.warn("Ignore outdated message",
|
|
274
|
+
const W = I(0);
|
|
275
|
+
return C(() => {
|
|
276
|
+
if (e.token && c.isSocketAvailable && a.current) {
|
|
277
|
+
let t = !1;
|
|
278
|
+
p.current ? p.current.token !== e.token && (a.current.unsubscribe(R(p.current.token)), t = !0) : t = !0, t && (p.current = a.current.subscribe(R(e.token)), W.current = 0, p.current.token = e.token, p.current.on("updated", ({ response: r }) => {
|
|
279
|
+
const n = +new Date(r.updatedAt);
|
|
280
|
+
if (n <= W.current) {
|
|
281
|
+
console.warn("Ignore outdated message", r);
|
|
290
282
|
return;
|
|
291
283
|
}
|
|
292
|
-
|
|
293
|
-
let { status:
|
|
294
|
-
|
|
284
|
+
W.current = n;
|
|
285
|
+
let { status: i, error: s } = r;
|
|
286
|
+
i === "forbidden" && (s = S.forbidden, i = "error"), e.status = i, e.mfaCode = r.mfaCode || 0, e.store = r, e.error = s, s && g(new Error(s), e?.store, A);
|
|
295
287
|
}));
|
|
296
288
|
}
|
|
297
|
-
}, [e.token,
|
|
289
|
+
}, [e.token, c.isSocketAvailable, a.current]), ke(w, ie()), xe(() => {
|
|
298
290
|
e.token && Y(e.status) === !1 && (e.checking = !1, setTimeout(() => {
|
|
299
|
-
|
|
291
|
+
w(!0);
|
|
300
292
|
}, 100));
|
|
301
293
|
}), { state: e, generate: y, cancelWhenScanned: ce };
|
|
302
294
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { default as t, default as r, default as s } from "./Connect/index.js";
|
|
2
2
|
import { default as n, default as d } from "./Button/index.js";
|
|
3
3
|
import { default as f, default as p } from "@arcblock/ux/lib/DIDLogo";
|
|
4
|
-
import { createSessionContext as _, createAuthServiceSessionContext as
|
|
4
|
+
import { createSessionContext as _, createAuthServiceSessionContext as x, createSessionContext as m } from "./Session/index.js";
|
|
5
5
|
import { OAuthConsumer as C, OAuthContext as T, OAuthProvider as i, useOAuth as I } from "./OAuth/context.js";
|
|
6
|
-
import { PasskeyConsumer as S, PasskeyContext as c, PasskeyProvider as O, usePasskey as
|
|
6
|
+
import { PasskeyConsumer as S, PasskeyContext as c, PasskeyProvider as O, usePasskey as g } from "./Passkey/context.js";
|
|
7
7
|
import { default as R } from "./Passkey/actions.js";
|
|
8
8
|
import { default as N } from "./User/use-did.js";
|
|
9
9
|
import { default as F } from "./User/wrap-did.js";
|
|
10
10
|
import { FederatedConsumer as K, FederatedContext as M, FederatedProvider as y, useFederatedContext as h } from "./Federated/context.js";
|
|
11
|
-
import { API_DID_PREFIX as V, BLOCKLET_SERVICE_PATH_PREFIX as v, BUSY_STATUS as b, CHECK_INTERVAL_TIME as B, CHECK_STATUS_INTERVAL as
|
|
12
|
-
import { createAxios as oe, debug as te, debugTmp as re, debugTmpInterval as se, decodeConnectUrl as ae, decodeKey as ne, decodeUrlParams as de, decrypt as Ee, encodeConnectUrl as fe, encodeKey as pe, encrypt as ue, formatCacheTtl as _e, getApiErrorMessage as
|
|
13
|
-
import { NotOpenError as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
18
|
-
import { EVENTS as
|
|
19
|
-
import { didSpacesIsRequired as
|
|
11
|
+
import { API_DID_PREFIX as V, BLOCKLET_SERVICE_PATH_PREFIX as v, BUSY_STATUS as b, CHECK_INTERVAL_TIME as B, CHECK_STATUS_INTERVAL as H, CSRF_TOKEN_STORAGE_KEY as W, DEFAULT_NAME as Y, DEFAULT_TIMEOUT as G, DEFAULT_WINDOW_TIMEOUT as X, DID_CONNECT_URL_PARAMS_NAME as w, DID_SPACES_BASE_URL as q, EXT_DOWNLOAD_URL as j, LANG_COOKIE_NAME as z, REFRESH_TOKEN_STORAGE_KEY as J, RELAY_SOCKET_PREFIX as Q, SESSION_TOKEN_STORAGE_KEY as Z, VERIFY_CODE_LENGTH as $ } from "./constant.js";
|
|
12
|
+
import { createAxios as oe, debug as te, debugTmp as re, debugTmpInterval as se, decodeConnectUrl as ae, decodeKey as ne, decodeUrlParams as de, decrypt as Ee, encodeConnectUrl as fe, encodeKey as pe, encrypt as ue, formatCacheTtl as _e, getApiErrorMessage as xe, getAppId as me, getBrowserLang as Ae, getConnectedInfo as Ce, getExtraHeaders as Te, getWebAuthnErrorMessage as ie, logger as Ie, openPopup as le, parseNextWorkflow as Se, parseTokenFromConnectUrl as ce, runPopup as Oe, sleep as ge, updateConnectedInfo as De, version as Re } from "./utils.js";
|
|
13
|
+
import { NotOpenError as Ne } from "./error.js";
|
|
14
|
+
import { default as Fe } from "@arcblock/ux/lib/SessionManager";
|
|
15
|
+
import { default as Ke } from "@arcblock/ux/lib/Address";
|
|
16
|
+
import { default as ye } from "@arcblock/ux/lib/Avatar";
|
|
17
|
+
import { default as ke } from "./Connect/use-connect.js";
|
|
18
|
+
import { EVENTS as ve } from "./Session/libs/constants.js";
|
|
19
|
+
import { didSpacesIsRequired as Be } from "./Session/libs/did-spaces.js";
|
|
20
20
|
import { loginFederatedMaster as We, mountFederatedIframe as Ye } from "./Session/libs/federated.js";
|
|
21
|
-
import { translations as
|
|
22
|
-
import { checkEnableAutoLogin as
|
|
23
|
-
import { SessionContext as
|
|
21
|
+
import { translations as Xe } from "./Session/libs/locales.js";
|
|
22
|
+
import { checkEnableAutoLogin as qe, getMobileVisitorId as je, login as ze } from "./Session/libs/login-mobile.js";
|
|
23
|
+
import { SessionContext as Qe } from "./Session/context.js";
|
|
24
24
|
export * from "@arcblock/ux/lib/Util/wallet";
|
|
25
|
-
import { getVisitorId as
|
|
25
|
+
import { getVisitorId as eo, setVisitorId as oo } from "@arcblock/ux/lib/Util";
|
|
26
26
|
export {
|
|
27
27
|
V as API_DID_PREFIX,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
Ke as Address,
|
|
29
|
+
ye as Avatar,
|
|
30
30
|
v as BLOCKLET_SERVICE_PATH_PREFIX,
|
|
31
31
|
b as BUSY_STATUS,
|
|
32
32
|
n as Button,
|
|
33
33
|
B as CHECK_INTERVAL_TIME,
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
H as CHECK_STATUS_INTERVAL,
|
|
35
|
+
W as CSRF_TOKEN_STORAGE_KEY,
|
|
36
36
|
t as Connect,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
Y as DEFAULT_NAME,
|
|
38
|
+
G as DEFAULT_TIMEOUT,
|
|
39
39
|
X as DEFAULT_WINDOW_TIMEOUT,
|
|
40
40
|
d as DIDButton,
|
|
41
41
|
r as DIDConnect,
|
|
@@ -43,14 +43,14 @@ export {
|
|
|
43
43
|
w as DID_CONNECT_URL_PARAMS_NAME,
|
|
44
44
|
q as DID_SPACES_BASE_URL,
|
|
45
45
|
s as DidConnect,
|
|
46
|
-
|
|
46
|
+
ve as EVENTS,
|
|
47
47
|
j as EXT_DOWNLOAD_URL,
|
|
48
48
|
K as FederatedConsumer,
|
|
49
49
|
M as FederatedContext,
|
|
50
50
|
y as FederatedProvider,
|
|
51
51
|
z as LANG_COOKIE_NAME,
|
|
52
52
|
p as Logo,
|
|
53
|
-
|
|
53
|
+
Ne as NotOpenError,
|
|
54
54
|
C as OAuthConsumer,
|
|
55
55
|
T as OAuthContext,
|
|
56
56
|
i as OAuthProvider,
|
|
@@ -62,14 +62,14 @@ export {
|
|
|
62
62
|
Q as RELAY_SOCKET_PREFIX,
|
|
63
63
|
Z as SESSION_TOKEN_STORAGE_KEY,
|
|
64
64
|
_ as Session,
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
Qe as SessionContext,
|
|
66
|
+
Fe as SessionManager,
|
|
67
67
|
$ as VERIFY_CODE_LENGTH,
|
|
68
68
|
F as WrapDid,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
qe as checkEnableAutoLogin,
|
|
70
|
+
x as createAuthServiceSessionContext,
|
|
71
71
|
oe as createAxios,
|
|
72
|
-
|
|
72
|
+
m as createSessionContext,
|
|
73
73
|
te as debug,
|
|
74
74
|
re as debugTmp,
|
|
75
75
|
se as debugTmpInterval,
|
|
@@ -77,34 +77,35 @@ export {
|
|
|
77
77
|
ne as decodeKey,
|
|
78
78
|
de as decodeUrlParams,
|
|
79
79
|
Ee as decrypt,
|
|
80
|
-
|
|
80
|
+
Be as didSpacesIsRequired,
|
|
81
81
|
fe as encodeConnectUrl,
|
|
82
82
|
pe as encodeKey,
|
|
83
83
|
ue as encrypt,
|
|
84
84
|
_e as formatCacheTtl,
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
xe as getApiErrorMessage,
|
|
86
|
+
me as getAppId,
|
|
87
87
|
Ae as getBrowserLang,
|
|
88
88
|
Ce as getConnectedInfo,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
ie as
|
|
93
|
-
|
|
89
|
+
Te as getExtraHeaders,
|
|
90
|
+
je as getMobileVisitorId,
|
|
91
|
+
eo as getVisitorId,
|
|
92
|
+
ie as getWebAuthnErrorMessage,
|
|
93
|
+
Ie as logger,
|
|
94
|
+
ze as login,
|
|
94
95
|
We as loginFederatedMaster,
|
|
95
96
|
Ye as mountFederatedIframe,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
le as openPopup,
|
|
98
|
+
Se as parseNextWorkflow,
|
|
99
|
+
ce as parseTokenFromConnectUrl,
|
|
100
|
+
Oe as runPopup,
|
|
101
|
+
oo as setVisitorId,
|
|
102
|
+
ge as sleep,
|
|
103
|
+
Xe as translations,
|
|
103
104
|
De as updateConnectedInfo,
|
|
104
|
-
|
|
105
|
+
ke as useConnect,
|
|
105
106
|
N as useDid,
|
|
106
107
|
h as useFederatedContext,
|
|
107
108
|
I as useOAuth,
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
g as usePasskey,
|
|
110
|
+
Re as version
|
|
110
111
|
};
|
package/lib/package.json.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { Buffer as a } from "buffer";
|
|
2
2
|
import h from "tweetnacl-sealedbox-js";
|
|
3
|
-
import { getCookieOptions as A, getVisitorId as
|
|
4
|
-
import { getVisitorId as
|
|
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
5
|
import c from "js-cookie";
|
|
6
|
-
import
|
|
6
|
+
import l from "lodash/isNil";
|
|
7
7
|
import T from "lodash/isString";
|
|
8
8
|
import m from "lodash/isUndefined";
|
|
9
|
-
import { createAxios as
|
|
9
|
+
import { createAxios as P, BlockletSDK as x } from "@blocklet/js-sdk";
|
|
10
10
|
import { withQuery as L } from "ufo";
|
|
11
11
|
import { isValid as w, isFromPublicKey as S } from "@arcblock/did";
|
|
12
|
-
import { getSafeUrl as
|
|
13
|
-
import { createDebug as u, createLogger as
|
|
14
|
-
import
|
|
15
|
-
import { DID_CONNECT_URL_PARAMS_NAME as f, DEFAULT_WINDOW_TIMEOUT as
|
|
16
|
-
import { NotOpenError as
|
|
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
17
|
export * from "@arcblock/ux/lib/Util/wallet";
|
|
18
|
-
const { version: O } =
|
|
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
19
|
function b(e) {
|
|
20
20
|
return (e + "===".slice((e.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
|
|
21
21
|
}
|
|
22
22
|
function _(e) {
|
|
23
23
|
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const se = (e) => _(window.btoa(e)), ie = (e) => window.atob(b(e)), ae = (e) => {
|
|
26
26
|
const o = new URL(e), r = decodeURIComponent(o.searchParams.get("url"));
|
|
27
27
|
return new URL(r).searchParams.get("_t_");
|
|
28
|
-
},
|
|
28
|
+
}, R = (e, o) => {
|
|
29
29
|
let r = o?.publisher;
|
|
30
30
|
if (!r) {
|
|
31
31
|
if (e?.agentDid)
|
|
@@ -37,40 +37,40 @@ const ne = (e) => _(window.btoa(e)), te = (e) => window.atob(b(e)), se = (e) =>
|
|
|
37
37
|
const o = {
|
|
38
38
|
connected_did: e.did || "",
|
|
39
39
|
connected_pk: e.pk || "",
|
|
40
|
-
connected_app:
|
|
40
|
+
connected_app: R(e.appInfo, e.memberAppInfo)
|
|
41
41
|
};
|
|
42
42
|
return e?.connectedWallet?.os && (o.connected_wallet_os = e.connectedWallet.os), o;
|
|
43
|
-
},
|
|
43
|
+
}, ce = (e, o = !1) => {
|
|
44
44
|
if (!e) return;
|
|
45
45
|
o || (e = z(e));
|
|
46
46
|
const r = A({
|
|
47
47
|
expireInDays: 7,
|
|
48
48
|
returnDomain: !1
|
|
49
49
|
});
|
|
50
|
-
!
|
|
51
|
-
},
|
|
52
|
-
const
|
|
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
53
|
Uint8Array.from(a.from(e, "base64")),
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
d(o),
|
|
55
|
+
d(r)
|
|
56
56
|
);
|
|
57
|
-
return JSON.parse(a.from(
|
|
58
|
-
},
|
|
59
|
-
const r = new URL(e),
|
|
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
60
|
baseUrl: r.origin,
|
|
61
61
|
prefix: r.pathname.replace(/\/auth$/, ""),
|
|
62
62
|
token: r.searchParams.get(o) || ""
|
|
63
63
|
};
|
|
64
|
-
if (!
|
|
64
|
+
if (!t.baseUrl)
|
|
65
65
|
throw new Error("Invalid next workflow: origin empty");
|
|
66
|
-
if (!
|
|
66
|
+
if (!t.token)
|
|
67
67
|
throw new Error("Invalid next workflow: token not found");
|
|
68
|
-
return
|
|
68
|
+
return t;
|
|
69
69
|
}, g = (e, o) => {
|
|
70
70
|
let r = e.message;
|
|
71
|
-
const { response:
|
|
72
|
-
return
|
|
73
|
-
},
|
|
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
74
|
if (!e)
|
|
75
75
|
return e;
|
|
76
76
|
if (!e.name)
|
|
@@ -87,27 +87,35 @@ const ne = (e) => _(window.btoa(e)), te = (e) => window.atob(b(e)), se = (e) =>
|
|
|
87
87
|
default:
|
|
88
88
|
return console.warn("Unhandled WebAuthn error type:", e.name), g(e, o);
|
|
89
89
|
}
|
|
90
|
-
},
|
|
91
|
-
const
|
|
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),
|
|
92
100
|
...e.headers,
|
|
93
101
|
"x-did-connect-version": O
|
|
94
|
-
},
|
|
102
|
+
}, n = P(
|
|
95
103
|
{
|
|
96
104
|
...e,
|
|
97
|
-
headers:
|
|
105
|
+
headers: t
|
|
98
106
|
},
|
|
99
107
|
{ lazy: o, lazyTime: r }
|
|
100
108
|
);
|
|
101
|
-
return
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
}),
|
|
105
|
-
},
|
|
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) => {
|
|
106
114
|
setTimeout(() => {
|
|
107
115
|
o();
|
|
108
116
|
}, e);
|
|
109
117
|
});
|
|
110
|
-
function
|
|
118
|
+
function ge() {
|
|
111
119
|
if (typeof window > "u")
|
|
112
120
|
return null;
|
|
113
121
|
const e = window.navigator.languages && window.navigator.languages[0] || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage || window.navigator.systemLanguage || null;
|
|
@@ -118,22 +126,22 @@ function we() {
|
|
|
118
126
|
en: "en"
|
|
119
127
|
}[e] || "en";
|
|
120
128
|
}
|
|
121
|
-
function
|
|
129
|
+
function he(e, o) {
|
|
122
130
|
return [void 0, null, ""].includes(e) ? o : e / 86400;
|
|
123
131
|
}
|
|
124
|
-
async function
|
|
132
|
+
async function be() {
|
|
125
133
|
const e = window.location.href;
|
|
126
134
|
try {
|
|
127
135
|
const o = new URL(e), r = o.searchParams.get(f);
|
|
128
136
|
if (r) {
|
|
129
137
|
o.searchParams.delete(f);
|
|
130
|
-
const
|
|
131
|
-
if (T(
|
|
132
|
-
const
|
|
133
|
-
m(
|
|
138
|
+
const t = JSON.parse(a.from(r, "base64").toString("utf-8"));
|
|
139
|
+
if (T(t.forceConnected) && m(t.sourceAppPid)) {
|
|
140
|
+
const s = await new x().user.getUserPublicInfo({ did: t.forceConnected });
|
|
141
|
+
m(s?.sourceAppPid) || (t.sourceAppPid = s.sourceAppPid);
|
|
134
142
|
}
|
|
135
143
|
return {
|
|
136
|
-
params:
|
|
144
|
+
params: t,
|
|
137
145
|
url: o.href
|
|
138
146
|
};
|
|
139
147
|
}
|
|
@@ -145,8 +153,8 @@ async function ge() {
|
|
|
145
153
|
url: e
|
|
146
154
|
};
|
|
147
155
|
}
|
|
148
|
-
const
|
|
149
|
-
const
|
|
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 = [
|
|
150
158
|
`left=${v}`,
|
|
151
159
|
`top=${k}`,
|
|
152
160
|
`width=${o}`,
|
|
@@ -156,61 +164,62 @@ const he = (e, { width: o = 680, height: r = 720, name: n = "did-connect:popup",
|
|
|
156
164
|
"scrollbars=yes",
|
|
157
165
|
"status=yes",
|
|
158
166
|
"popup=yes"
|
|
159
|
-
], p = window.open("",
|
|
167
|
+
], p = window.open("", t, y.join(","));
|
|
160
168
|
if (p === null)
|
|
161
|
-
throw new
|
|
162
|
-
return p.location.href = L(
|
|
169
|
+
throw new W();
|
|
170
|
+
return p.location.href = L(i, {
|
|
163
171
|
// NOTICE: 携带当前页面的 origin,用于在 popup 中通过该参数判断是否可以发送 postMessage,即使该参数被伪造,最终也只有该域名能接收到消息,所以没有关系
|
|
164
172
|
opener: window.location.origin
|
|
165
173
|
}), p;
|
|
166
|
-
},
|
|
167
|
-
let
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
170
|
-
if (
|
|
171
|
-
console.error(
|
|
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);
|
|
172
180
|
return;
|
|
173
181
|
}
|
|
174
182
|
setTimeout(() => {
|
|
175
|
-
e.popup?.close(), clearTimeout(
|
|
176
|
-
}, e.closeTimeout || 0), o(
|
|
183
|
+
e.popup?.close(), clearTimeout(n), clearInterval(t), window.removeEventListener("message", s, !1);
|
|
184
|
+
}, e.closeTimeout || 0), o(i);
|
|
177
185
|
}
|
|
178
186
|
};
|
|
179
|
-
|
|
187
|
+
n = setTimeout(
|
|
180
188
|
() => {
|
|
181
|
-
clearInterval(
|
|
189
|
+
clearInterval(t), r(new Error("Timeout")), window.removeEventListener("message", s, !1);
|
|
182
190
|
},
|
|
183
|
-
(e.timeoutInSeconds ||
|
|
184
|
-
),
|
|
185
|
-
e.popup?.closed && (clearInterval(
|
|
186
|
-
}, 1e3), window.addEventListener("message",
|
|
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);
|
|
187
195
|
});
|
|
188
196
|
export {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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,
|
|
201
209
|
g as getApiErrorMessage,
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
R as getAppId,
|
|
211
|
+
ge as getBrowserLang,
|
|
204
212
|
z as getConnectedInfo,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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,
|
|
215
224
|
O as version
|
|
216
225
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-connect-react",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.10",
|
|
4
4
|
"description": "Client side library to work with DID Connect by ArcBlock.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@arcblock/bridge": "3.3.
|
|
35
|
+
"@arcblock/bridge": "3.3.10",
|
|
36
36
|
"@arcblock/did": "^1.27.16",
|
|
37
|
-
"@arcblock/icons": "3.3.
|
|
38
|
-
"@arcblock/react-hooks": "3.3.
|
|
37
|
+
"@arcblock/icons": "3.3.10",
|
|
38
|
+
"@arcblock/react-hooks": "3.3.10",
|
|
39
39
|
"@arcblock/ws": "^1.27.16",
|
|
40
40
|
"@blocklet/constant": "^1.17.7",
|
|
41
41
|
"@fontsource/lexend": "^5.2.9",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
82
82
|
"jest": "^29.7.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "6c98492b766cb7f7486f3a81f3d4e4b0936af163"
|
|
85
85
|
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
createAxios,
|
|
20
20
|
sleep,
|
|
21
21
|
getConnectedInfo,
|
|
22
|
+
getExtraHeaders,
|
|
22
23
|
} from '../../utils';
|
|
23
24
|
|
|
24
25
|
import translations from '../assets/locale';
|
|
@@ -31,19 +32,6 @@ function getSocketHost(baseUrl) {
|
|
|
31
32
|
return new URL(targetUrl).host;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function getExtraHeaders(baseUrl) {
|
|
35
|
-
const headers = {};
|
|
36
|
-
const authUrl = baseUrl || window.location.href;
|
|
37
|
-
|
|
38
|
-
if (authUrl) {
|
|
39
|
-
const { hostname, protocol, port } = new URL(authUrl);
|
|
40
|
-
headers['x-real-hostname'] = hostname;
|
|
41
|
-
headers['x-real-port'] = port;
|
|
42
|
-
headers['x-real-protocol'] = protocol.endsWith(':') ? protocol.substring(0, protocol.length - 1) : protocol;
|
|
43
|
-
}
|
|
44
|
-
return headers;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
35
|
const fns = {};
|
|
48
36
|
function createTokenFn({ action, prefix, checkFn, extraParams, baseUrl }) {
|
|
49
37
|
const key = `${prefix}/token?${stringifyQuery(extraParams)}`;
|
package/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import SealedBox from 'tweetnacl-sealedbox-js';
|
|
3
|
-
import { getCookieOptions, setVisitorId, getVisitorId } from '@arcblock/ux/lib/Util';
|
|
3
|
+
import { getCookieOptions, setVisitorId, getVisitorId, isUrl } from '@arcblock/ux/lib/Util';
|
|
4
4
|
import Cookie from 'js-cookie';
|
|
5
5
|
import isNil from 'lodash/isNil';
|
|
6
6
|
import isString from 'lodash/isString';
|
|
@@ -202,8 +202,24 @@ export const getWebAuthnErrorMessage = (err, defaultMessage, t) => {
|
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
204
|
|
|
205
|
+
export const getExtraHeaders = (baseUrl) => {
|
|
206
|
+
const headers = {};
|
|
207
|
+
// 如果 baseUrl 是有效的 url,则使用 baseUrl,否则使用当前页面的 url
|
|
208
|
+
// 避免传入的 baseUrl 是相对路径,导致 new URL 失败
|
|
209
|
+
const authUrl = isUrl(baseUrl) ? baseUrl : window.location.href;
|
|
210
|
+
|
|
211
|
+
if (authUrl) {
|
|
212
|
+
const { hostname, protocol, port } = new URL(authUrl);
|
|
213
|
+
headers['x-real-hostname'] = hostname;
|
|
214
|
+
headers['x-real-port'] = port;
|
|
215
|
+
headers['x-real-protocol'] = protocol.endsWith(':') ? protocol.substring(0, protocol.length - 1) : protocol;
|
|
216
|
+
}
|
|
217
|
+
return headers;
|
|
218
|
+
};
|
|
219
|
+
|
|
205
220
|
export const createAxios = (options = {}, { lazy = false, lazyTime = 300 } = {}) => {
|
|
206
221
|
const mergedHeaders = {
|
|
222
|
+
...getExtraHeaders(options.baseURL),
|
|
207
223
|
...options.headers,
|
|
208
224
|
'x-did-connect-version': version,
|
|
209
225
|
};
|