@arcblock/did-connect-react 3.1.56 → 3.1.58
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/Session/hooks/use-session-token.js +76 -76
- package/lib/Session/index.js +270 -266
- package/lib/Storage/engine/cookie.js +6 -5
- package/lib/Storage/engine/local-storage.js +4 -3
- package/lib/index.js +68 -66
- package/lib/package.json.js +1 -1
- package/lib/utils.js +69 -67
- package/package.json +5 -5
- package/src/Session/hooks/use-session-token.js +17 -1
- package/src/Session/index.jsx +10 -2
- package/src/Storage/engine/cookie.js +2 -0
- package/src/Storage/engine/local-storage.js +2 -0
- package/src/utils.js +2 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import o from "js-cookie";
|
|
2
2
|
import { getCookieOptions as t } from "@arcblock/ux/lib/Util";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { debugTmp as s } from "../../utils.js";
|
|
4
|
+
class a {
|
|
5
|
+
constructor(e, r) {
|
|
6
|
+
this.storageKey = e, this.options = r || {};
|
|
6
7
|
}
|
|
7
8
|
setToken(e) {
|
|
8
9
|
return o.set(this.storageKey, e, {
|
|
@@ -13,9 +14,9 @@ class g {
|
|
|
13
14
|
return o.get(this.storageKey);
|
|
14
15
|
}
|
|
15
16
|
removeToken() {
|
|
16
|
-
return o.remove(this.storageKey, t(this.options));
|
|
17
|
+
return s("[CookieStorageEngine] removeToken"), o.remove(this.storageKey, t(this.options));
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
20
|
-
|
|
21
|
+
a as default
|
|
21
22
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import o from "jwt-decode";
|
|
2
|
-
|
|
2
|
+
import { debugTmp as r } from "../../utils.js";
|
|
3
|
+
class f {
|
|
3
4
|
constructor(e) {
|
|
4
5
|
this.storageKey = e;
|
|
5
6
|
}
|
|
@@ -27,10 +28,10 @@ class a {
|
|
|
27
28
|
return t;
|
|
28
29
|
}
|
|
29
30
|
removeToken() {
|
|
30
|
-
if (!(typeof window > "u" || typeof window.localStorage > "u"))
|
|
31
|
+
if (r("[LocalStorageEngine] removeToken"), !(typeof window > "u" || typeof window.localStorage > "u"))
|
|
31
32
|
return localStorage.removeItem(this.storageKey);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
export {
|
|
35
|
-
|
|
36
|
+
f as default
|
|
36
37
|
};
|
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
|
|
5
|
-
import { OAuthConsumer as
|
|
6
|
-
import { PasskeyConsumer as
|
|
4
|
+
import { createSessionContext as _, createAuthServiceSessionContext as m, createSessionContext as x } from "./Session/index.js";
|
|
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 D } 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
|
|
12
|
-
import { createAxios as oe, debug as te,
|
|
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
|
|
20
|
-
import { loginFederatedMaster as
|
|
21
|
-
import { translations as
|
|
22
|
-
import { checkEnableAutoLogin as
|
|
23
|
-
import { SessionContext 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 W, CSRF_TOKEN_STORAGE_KEY as Y, DEFAULT_NAME as G, DEFAULT_TIMEOUT as H, 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 me, getAppId as xe, getBrowserLang as Ae, getConnectedInfo as Ce, getWebAuthnErrorMessage as Te, logger as ie, openPopup as Ie, parseNextWorkflow as le, parseTokenFromConnectUrl as Se, runPopup as ce, sleep as Oe, updateConnectedInfo as De, version as ge } from "./utils.js";
|
|
13
|
+
import { NotOpenError as Le } from "./error.js";
|
|
14
|
+
import { default as Pe } from "@arcblock/ux/lib/SessionManager";
|
|
15
|
+
import { default as Ue } from "@arcblock/ux/lib/Address";
|
|
16
|
+
import { default as Me } from "@arcblock/ux/lib/Avatar";
|
|
17
|
+
import { default as he } 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
|
+
import { loginFederatedMaster as We, mountFederatedIframe as Ye } from "./Session/libs/federated.js";
|
|
21
|
+
import { translations as He } from "./Session/libs/locales.js";
|
|
22
|
+
import { checkEnableAutoLogin as we, getMobileVisitorId as qe, login as je } from "./Session/libs/login-mobile.js";
|
|
23
|
+
import { SessionContext as Je } from "./Session/context.js";
|
|
24
24
|
export * from "@arcblock/ux/lib/Util/wallet";
|
|
25
|
-
import { getVisitorId as
|
|
25
|
+
import { getVisitorId as $e, setVisitorId as eo } from "@arcblock/ux/lib/Util";
|
|
26
26
|
export {
|
|
27
27
|
V as API_DID_PREFIX,
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
Ue as Address,
|
|
29
|
+
Me as Avatar,
|
|
30
30
|
v as BLOCKLET_SERVICE_PATH_PREFIX,
|
|
31
|
-
|
|
31
|
+
b as BUSY_STATUS,
|
|
32
32
|
n as Button,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
B as CHECK_INTERVAL_TIME,
|
|
34
|
+
W as CHECK_STATUS_INTERVAL,
|
|
35
|
+
Y as CSRF_TOKEN_STORAGE_KEY,
|
|
36
36
|
t as Connect,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
G as DEFAULT_NAME,
|
|
38
|
+
H as DEFAULT_TIMEOUT,
|
|
39
39
|
X as DEFAULT_WINDOW_TIMEOUT,
|
|
40
40
|
d as DIDButton,
|
|
41
41
|
r as DIDConnect,
|
|
@@ -43,66 +43,68 @@ 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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
Le as NotOpenError,
|
|
54
|
+
C as OAuthConsumer,
|
|
55
|
+
T as OAuthContext,
|
|
56
|
+
i as OAuthProvider,
|
|
57
57
|
R as PasskeyActions,
|
|
58
|
-
|
|
58
|
+
S as PasskeyConsumer,
|
|
59
59
|
c as PasskeyContext,
|
|
60
60
|
O as PasskeyProvider,
|
|
61
61
|
J as REFRESH_TOKEN_STORAGE_KEY,
|
|
62
62
|
Q as RELAY_SOCKET_PREFIX,
|
|
63
63
|
Z as SESSION_TOKEN_STORAGE_KEY,
|
|
64
64
|
_ as Session,
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
Je as SessionContext,
|
|
66
|
+
Pe as SessionManager,
|
|
67
67
|
$ as VERIFY_CODE_LENGTH,
|
|
68
68
|
F as WrapDid,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
we as checkEnableAutoLogin,
|
|
70
|
+
m as createAuthServiceSessionContext,
|
|
71
71
|
oe as createAxios,
|
|
72
|
-
|
|
72
|
+
x as createSessionContext,
|
|
73
73
|
te as debug,
|
|
74
|
-
re as
|
|
75
|
-
se as
|
|
76
|
-
ae as
|
|
77
|
-
ne as
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
fe as
|
|
82
|
-
pe as
|
|
83
|
-
ue as
|
|
84
|
-
_e as
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
Ie as
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
74
|
+
re as debugTmp,
|
|
75
|
+
se as debugTmpInterval,
|
|
76
|
+
ae as decodeConnectUrl,
|
|
77
|
+
ne as decodeKey,
|
|
78
|
+
de as decodeUrlParams,
|
|
79
|
+
Ee as decrypt,
|
|
80
|
+
be as didSpacesIsRequired,
|
|
81
|
+
fe as encodeConnectUrl,
|
|
82
|
+
pe as encodeKey,
|
|
83
|
+
ue as encrypt,
|
|
84
|
+
_e as formatCacheTtl,
|
|
85
|
+
me as getApiErrorMessage,
|
|
86
|
+
xe as getAppId,
|
|
87
|
+
Ae as getBrowserLang,
|
|
88
|
+
Ce as getConnectedInfo,
|
|
89
|
+
qe as getMobileVisitorId,
|
|
90
|
+
$e as getVisitorId,
|
|
91
|
+
Te as getWebAuthnErrorMessage,
|
|
92
|
+
ie as logger,
|
|
93
|
+
je as login,
|
|
94
|
+
We as loginFederatedMaster,
|
|
95
|
+
Ye as mountFederatedIframe,
|
|
96
|
+
Ie as openPopup,
|
|
97
|
+
le as parseNextWorkflow,
|
|
98
|
+
Se as parseTokenFromConnectUrl,
|
|
99
|
+
ce as runPopup,
|
|
100
|
+
eo as setVisitorId,
|
|
101
|
+
Oe as sleep,
|
|
102
|
+
He as translations,
|
|
103
|
+
De as updateConnectedInfo,
|
|
104
|
+
he as useConnect,
|
|
103
105
|
N as useDid,
|
|
104
106
|
h as useFederatedContext,
|
|
105
107
|
I as useOAuth,
|
|
106
108
|
D as usePasskey,
|
|
107
|
-
|
|
109
|
+
ge as version
|
|
108
110
|
};
|
package/lib/package.json.js
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { Buffer as a } from "buffer";
|
|
2
|
-
import
|
|
3
|
-
import { getCookieOptions as
|
|
4
|
-
import { getVisitorId as
|
|
2
|
+
import h from "tweetnacl-sealedbox-js";
|
|
3
|
+
import { getCookieOptions as A, getVisitorId as U } from "@arcblock/ux/lib/Util";
|
|
4
|
+
import { getVisitorId as ke, setVisitorId as ye } from "@arcblock/ux/lib/Util";
|
|
5
5
|
import c from "js-cookie";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
6
|
+
import d from "lodash/isNil";
|
|
7
|
+
import T from "lodash/isString";
|
|
8
|
+
import m from "lodash/isUndefined";
|
|
9
9
|
import { createAxios as E, BlockletSDK as P } from "@blocklet/js-sdk";
|
|
10
|
-
import { withQuery as
|
|
11
|
-
import { isValid as
|
|
12
|
-
import { getSafeUrl as
|
|
13
|
-
import { createDebug as
|
|
14
|
-
import
|
|
15
|
-
import { DID_CONNECT_URL_PARAMS_NAME as
|
|
16
|
-
import { NotOpenError as
|
|
10
|
+
import { withQuery as L } from "ufo";
|
|
11
|
+
import { isValid as w, isFromPublicKey as S } from "@arcblock/did";
|
|
12
|
+
import { getSafeUrl as x } from "@arcblock/ux/lib/Util/security";
|
|
13
|
+
import { createDebug as u, createLogger as C } from "@arcblock/ux/lib/Util/logger";
|
|
14
|
+
import I from "./package.json.js";
|
|
15
|
+
import { DID_CONNECT_URL_PARAMS_NAME as f, DEFAULT_WINDOW_TIMEOUT as N } from "./constant.js";
|
|
16
|
+
import { NotOpenError as D } from "./error.js";
|
|
17
17
|
export * from "@arcblock/ux/lib/Util/wallet";
|
|
18
|
-
const { version: O } =
|
|
19
|
-
function
|
|
18
|
+
const { version: O } = I, Z = u("did-connect"), ee = u("did-connect:tmp"), re = u("did-connect:tmp-interval"), oe = C("did-connect");
|
|
19
|
+
function b(e) {
|
|
20
20
|
return (e + "===".slice((e.length + 3) % 4)).replace(/-/g, "+").replace(/_/g, "/");
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function _(e) {
|
|
23
23
|
return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
24
24
|
}
|
|
25
|
-
const
|
|
25
|
+
const ne = (e) => _(window.btoa(e)), te = (e) => window.atob(b(e)), se = (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
|
}, W = (e, o) => {
|
|
@@ -40,22 +40,22 @@ const re = (e) => b(window.btoa(e)), oe = (e) => window.atob(h(e)), ne = (e) =>
|
|
|
40
40
|
connected_app: W(e.appInfo, e.memberAppInfo)
|
|
41
41
|
};
|
|
42
42
|
return e?.connectedWallet?.os && (o.connected_wallet_os = e.connectedWallet.os), o;
|
|
43
|
-
},
|
|
43
|
+
}, ie = (e, o = !1) => {
|
|
44
44
|
if (!e) return;
|
|
45
45
|
o || (e = z(e));
|
|
46
|
-
const r =
|
|
46
|
+
const r = A({
|
|
47
47
|
expireInDays: 7,
|
|
48
48
|
returnDomain: !1
|
|
49
49
|
});
|
|
50
|
-
!
|
|
51
|
-
},
|
|
52
|
-
const n =
|
|
50
|
+
!d(e.connected_did) && !d(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)), !d(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
|
+
}, ae = (e) => _(a.from(e).toString("base64")), l = (e) => Uint8Array.from(a.from(b(e), "base64")), ce = (e, o, r) => {
|
|
52
|
+
const n = h.open(
|
|
53
53
|
Uint8Array.from(a.from(e, "base64")),
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
l(o),
|
|
55
|
+
l(r)
|
|
56
56
|
);
|
|
57
57
|
return JSON.parse(a.from(n).toString("utf8"));
|
|
58
|
-
},
|
|
58
|
+
}, pe = (e, o) => a.from(h.seal(Uint8Array.from(a.from(e)), l(o))).toString("base64"), de = (e, o = "_t_") => {
|
|
59
59
|
const r = new URL(e), n = {
|
|
60
60
|
baseUrl: r.origin,
|
|
61
61
|
prefix: r.pathname.replace(/\/auth$/, ""),
|
|
@@ -66,15 +66,15 @@ const re = (e) => b(window.btoa(e)), oe = (e) => window.atob(h(e)), ne = (e) =>
|
|
|
66
66
|
if (!n.token)
|
|
67
67
|
throw new Error("Invalid next workflow: token not found");
|
|
68
68
|
return n;
|
|
69
|
-
},
|
|
69
|
+
}, g = (e, o) => {
|
|
70
70
|
let r = e.message;
|
|
71
71
|
const { response: n } = e;
|
|
72
72
|
return n && (r = n.data?.error || n.data?.message || n.data || o, r = typeof r == "object" ? o : r), r;
|
|
73
|
-
},
|
|
73
|
+
}, le = (e, o, r) => {
|
|
74
74
|
if (!e)
|
|
75
75
|
return e;
|
|
76
76
|
if (!e.name)
|
|
77
|
-
return
|
|
77
|
+
return g(e, o);
|
|
78
78
|
switch (e.name) {
|
|
79
79
|
case "NotAllowedError":
|
|
80
80
|
return r ? r("webauthn.error.canceled") : "Authentication was canceled";
|
|
@@ -85,9 +85,9 @@ const re = (e) => b(window.btoa(e)), oe = (e) => window.atob(h(e)), ne = (e) =>
|
|
|
85
85
|
case "AbortError":
|
|
86
86
|
return r ? r("webauthn.error.aborted") : "Authentication was aborted";
|
|
87
87
|
default:
|
|
88
|
-
return console.warn("Unhandled WebAuthn error type:", e.name),
|
|
88
|
+
return console.warn("Unhandled WebAuthn error type:", e.name), g(e, o);
|
|
89
89
|
}
|
|
90
|
-
},
|
|
90
|
+
}, ue = (e = {}, { lazy: o = !1, lazyTime: r = 300 } = {}) => {
|
|
91
91
|
const n = {
|
|
92
92
|
...e.headers,
|
|
93
93
|
"x-did-connect-version": O
|
|
@@ -99,15 +99,15 @@ const re = (e) => b(window.btoa(e)), oe = (e) => window.atob(h(e)), ne = (e) =>
|
|
|
99
99
|
{ lazy: o, lazyTime: r }
|
|
100
100
|
);
|
|
101
101
|
return i.interceptors.request.use((t) => {
|
|
102
|
-
const s =
|
|
102
|
+
const s = U();
|
|
103
103
|
return s && (t.headers["x-blocklet-visitor-id"] = s), t;
|
|
104
104
|
}), i;
|
|
105
|
-
},
|
|
105
|
+
}, me = (e = 0) => new Promise((o) => {
|
|
106
106
|
setTimeout(() => {
|
|
107
107
|
o();
|
|
108
108
|
}, e);
|
|
109
109
|
});
|
|
110
|
-
function
|
|
110
|
+
function we() {
|
|
111
111
|
if (typeof window > "u")
|
|
112
112
|
return null;
|
|
113
113
|
const e = window.navigator.languages && window.navigator.languages[0] || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage || window.navigator.systemLanguage || null;
|
|
@@ -118,19 +118,19 @@ function de() {
|
|
|
118
118
|
en: "en"
|
|
119
119
|
}[e] || "en";
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function fe(e, o) {
|
|
122
122
|
return [void 0, null, ""].includes(e) ? o : e / 86400;
|
|
123
123
|
}
|
|
124
|
-
async function
|
|
124
|
+
async function ge() {
|
|
125
125
|
const e = window.location.href;
|
|
126
126
|
try {
|
|
127
|
-
const o = new URL(e), r = o.searchParams.get(
|
|
127
|
+
const o = new URL(e), r = o.searchParams.get(f);
|
|
128
128
|
if (r) {
|
|
129
|
-
o.searchParams.delete(
|
|
129
|
+
o.searchParams.delete(f);
|
|
130
130
|
const n = JSON.parse(a.from(r, "base64").toString("utf-8"));
|
|
131
|
-
if (
|
|
131
|
+
if (T(n.forceConnected) && m(n.sourceAppPid)) {
|
|
132
132
|
const t = await new P().user.getUserPublicInfo({ did: n.forceConnected });
|
|
133
|
-
|
|
133
|
+
m(t?.sourceAppPid) || (n.sourceAppPid = t.sourceAppPid);
|
|
134
134
|
}
|
|
135
135
|
return {
|
|
136
136
|
params: n,
|
|
@@ -145,9 +145,9 @@ async function we() {
|
|
|
145
145
|
url: e
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
const s =
|
|
150
|
-
`left=${
|
|
148
|
+
const he = (e, { width: o = 680, height: r = 720, name: n = "did-connect:popup", offsetX: i = 0, offsetY: t = 0 } = {}) => {
|
|
149
|
+
const s = x(e, { allowDomains: null }), v = window.screenX + (window.innerWidth - o) / 2 + i, k = window.screenY + (window.innerHeight - r) / 2 + t, y = [
|
|
150
|
+
`left=${v}`,
|
|
151
151
|
`top=${k}`,
|
|
152
152
|
`width=${o}`,
|
|
153
153
|
`height=${r}`,
|
|
@@ -158,12 +158,12 @@ const fe = (e, { width: o = 680, height: r = 720, name: n = "did-connect:popup",
|
|
|
158
158
|
"popup=yes"
|
|
159
159
|
], p = window.open("", n, y.join(","));
|
|
160
160
|
if (p === null)
|
|
161
|
-
throw new
|
|
162
|
-
return p.location.href =
|
|
161
|
+
throw new D();
|
|
162
|
+
return p.location.href = L(s, {
|
|
163
163
|
// NOTICE: 携带当前页面的 origin,用于在 popup 中通过该参数判断是否可以发送 postMessage,即使该参数被伪造,最终也只有该域名能接收到消息,所以没有关系
|
|
164
164
|
opener: window.location.origin
|
|
165
165
|
}), p;
|
|
166
|
-
},
|
|
166
|
+
}, be = (e) => new Promise((o, r) => {
|
|
167
167
|
let n, i;
|
|
168
168
|
const t = ({ data: s }) => {
|
|
169
169
|
if (s && s.type === "authorization_response") {
|
|
@@ -180,35 +180,37 @@ const fe = (e, { width: o = 680, height: r = 720, name: n = "did-connect:popup",
|
|
|
180
180
|
() => {
|
|
181
181
|
clearInterval(n), r(new Error("Timeout")), window.removeEventListener("message", t, !1);
|
|
182
182
|
},
|
|
183
|
-
(e.timeoutInSeconds ||
|
|
183
|
+
(e.timeoutInSeconds || N) * 1e3
|
|
184
184
|
), n = setInterval(() => {
|
|
185
185
|
e.popup?.closed && (clearInterval(n), clearTimeout(i), window.removeEventListener("message", t, !1), r(new Error("Popup closed")));
|
|
186
186
|
}, 1e3), window.addEventListener("message", t);
|
|
187
187
|
});
|
|
188
188
|
export {
|
|
189
|
-
|
|
189
|
+
ue as createAxios,
|
|
190
190
|
Z as debug,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
ee as debugTmp,
|
|
192
|
+
re as debugTmpInterval,
|
|
193
|
+
te as decodeConnectUrl,
|
|
194
|
+
l as decodeKey,
|
|
195
|
+
ge as decodeUrlParams,
|
|
196
|
+
ce as decrypt,
|
|
197
|
+
ne as encodeConnectUrl,
|
|
198
|
+
ae as encodeKey,
|
|
199
|
+
pe as encrypt,
|
|
200
|
+
fe as formatCacheTtl,
|
|
201
|
+
g as getApiErrorMessage,
|
|
200
202
|
W as getAppId,
|
|
201
|
-
|
|
203
|
+
we as getBrowserLang,
|
|
202
204
|
z as getConnectedInfo,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
ke as getVisitorId,
|
|
206
|
+
le as getWebAuthnErrorMessage,
|
|
207
|
+
oe as logger,
|
|
208
|
+
he as openPopup,
|
|
209
|
+
de as parseNextWorkflow,
|
|
210
|
+
se as parseTokenFromConnectUrl,
|
|
211
|
+
be as runPopup,
|
|
212
|
+
ye as setVisitorId,
|
|
213
|
+
me as sleep,
|
|
214
|
+
ie as updateConnectedInfo,
|
|
213
215
|
O as version
|
|
214
216
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/did-connect-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.58",
|
|
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.1.
|
|
35
|
+
"@arcblock/bridge": "3.1.58",
|
|
36
36
|
"@arcblock/did": "^1.27.2",
|
|
37
|
-
"@arcblock/icons": "3.1.
|
|
38
|
-
"@arcblock/react-hooks": "3.1.
|
|
37
|
+
"@arcblock/icons": "3.1.58",
|
|
38
|
+
"@arcblock/react-hooks": "3.1.58",
|
|
39
39
|
"@arcblock/ws": "^1.27.2",
|
|
40
40
|
"@fontsource/lexend": "^5.2.9",
|
|
41
41
|
"@iconify-icons/logos": "^1.2.36",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
81
81
|
"jest": "^29.7.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "126e58b5963d5824c397169e26887a09981693e9"
|
|
84
84
|
}
|
|
@@ -11,7 +11,16 @@ import noop from 'lodash/noop';
|
|
|
11
11
|
import { ReactGA } from '@arcblock/ux/lib/withTracker';
|
|
12
12
|
import { GA_LAST_SOURCE_PROVIDER } from '@arcblock/ux/lib/withTracker/constant';
|
|
13
13
|
import createService from '../../Service';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
createAxios,
|
|
16
|
+
getBrowserLang,
|
|
17
|
+
decrypt as _decrypt,
|
|
18
|
+
sleep,
|
|
19
|
+
logger,
|
|
20
|
+
debug,
|
|
21
|
+
debugTmp,
|
|
22
|
+
debugTmpInterval,
|
|
23
|
+
} from '../../utils';
|
|
15
24
|
import { CHECK_INTERVAL_TIME, LANG_COOKIE_NAME } from '../../constant';
|
|
16
25
|
|
|
17
26
|
class ErrorToken extends Error {}
|
|
@@ -44,6 +53,7 @@ export default function useSessionToken({
|
|
|
44
53
|
});
|
|
45
54
|
}, [serviceHost]);
|
|
46
55
|
const removeToken = () => {
|
|
56
|
+
debugTmp('[removeToken] useSessionToken -> removeToken');
|
|
47
57
|
removeSessionToken();
|
|
48
58
|
removeRefreshToken();
|
|
49
59
|
};
|
|
@@ -56,6 +66,7 @@ export default function useSessionToken({
|
|
|
56
66
|
serviceHost,
|
|
57
67
|
authServicePrefix: pageState.prefix,
|
|
58
68
|
onRefreshTokenError() {
|
|
69
|
+
debugTmp('[removeToken] useSessionToken -> createService: onRefreshTokenError');
|
|
59
70
|
removeToken();
|
|
60
71
|
// HACK: 在使用 useReactive 后,即使重复的给子字段赋值为 null,也会引起组件的重渲染,所以对于定时循环来说,一定要避免这一点,防止无效的赋值引起页面重渲染
|
|
61
72
|
if (state.user) {
|
|
@@ -73,6 +84,7 @@ export default function useSessionToken({
|
|
|
73
84
|
Cookie.remove('connected_pk', cookieOptions);
|
|
74
85
|
Cookie.remove('connected_app', cookieOptions);
|
|
75
86
|
Cookie.remove('connected_wallet_os', cookieOptions);
|
|
87
|
+
debugTmpInterval('[removeToken] clearSession-interval');
|
|
76
88
|
removeToken();
|
|
77
89
|
};
|
|
78
90
|
|
|
@@ -119,6 +131,7 @@ export default function useSessionToken({
|
|
|
119
131
|
|
|
120
132
|
if (status === 400) {
|
|
121
133
|
// NOTE: 如果通过多种方式传递了 token,服务端会报 400 的错误,需要移除现有的 token
|
|
134
|
+
debugTmp('[removeToken] useSessionToken -> _refresh: status 400');
|
|
122
135
|
removeToken();
|
|
123
136
|
state.user = null;
|
|
124
137
|
state.error = '';
|
|
@@ -218,6 +231,7 @@ export default function useSessionToken({
|
|
|
218
231
|
if (err instanceof ErrorToken) {
|
|
219
232
|
console.warn('refresh token failed, remove all tokens');
|
|
220
233
|
setRetryCount(0);
|
|
234
|
+
debugTmp('[removeToken] useSessionToken -> handleRefreshToken: refresh token failed, remove all tokens');
|
|
221
235
|
removeToken();
|
|
222
236
|
setIntervalTime(CHECK_INTERVAL_TIME);
|
|
223
237
|
} else {
|
|
@@ -263,6 +277,7 @@ export default function useSessionToken({
|
|
|
263
277
|
if (refreshToken) {
|
|
264
278
|
handleRefreshToken(false, true);
|
|
265
279
|
} else {
|
|
280
|
+
debugTmpInterval('[clearSession-interval] useSessionToken -> checkToken: empty refreshToken');
|
|
266
281
|
clearSession();
|
|
267
282
|
// HACK: 在使用 useReactive 后,即使重复的给子字段赋值为 null,也会引起组件的重渲染,所以对于定时循环来说,一定要避免这一点,防止无效的赋值引起页面重渲染
|
|
268
283
|
if (state.user) {
|
|
@@ -301,6 +316,7 @@ export default function useSessionToken({
|
|
|
301
316
|
if (sessionToken || refreshToken) {
|
|
302
317
|
await handleRefreshUser();
|
|
303
318
|
} else {
|
|
319
|
+
debug('[clearSession] syncSessionSate: empty sessionToken and refreshToken');
|
|
304
320
|
clearSession();
|
|
305
321
|
if (state.user) {
|
|
306
322
|
state.user = null;
|
package/src/Session/index.jsx
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
decodeUrlParams,
|
|
42
42
|
logger,
|
|
43
43
|
debug,
|
|
44
|
+
debugTmp,
|
|
44
45
|
} from '../utils';
|
|
45
46
|
import WindowFocusAware from './window-focus-aware';
|
|
46
47
|
import { OAuthProvider, useOAuth, OAuthConsumer, OAuthContext } from '../OAuth';
|
|
@@ -578,6 +579,8 @@ function createSessionContext(
|
|
|
578
579
|
bridge.callArc('onLogout', logoutData);
|
|
579
580
|
}
|
|
580
581
|
|
|
582
|
+
debugTmp('[clearSession] createSessionContext -> logout:');
|
|
583
|
+
|
|
581
584
|
clearSession();
|
|
582
585
|
closeConnect();
|
|
583
586
|
state.user = null;
|
|
@@ -1493,6 +1496,11 @@ function createSessionContext(
|
|
|
1493
1496
|
const actualApp = getAppId();
|
|
1494
1497
|
|
|
1495
1498
|
if (props.autoDisconnect && connectedApp && actualApp && connectedApp !== actualApp) {
|
|
1499
|
+
debugTmp('[clearSession] createSessionContext -> SessionProvider -> useMount: autoDisconnect', {
|
|
1500
|
+
autoDisconnect: props.autoDisconnect,
|
|
1501
|
+
connectedApp,
|
|
1502
|
+
actualApp,
|
|
1503
|
+
});
|
|
1496
1504
|
clearSession();
|
|
1497
1505
|
state.initialized = true;
|
|
1498
1506
|
if (pageState.autoConnect) {
|
|
@@ -1582,8 +1590,8 @@ function createSessionContext(
|
|
|
1582
1590
|
|
|
1583
1591
|
try {
|
|
1584
1592
|
// await tryAutoLoginFederated();
|
|
1585
|
-
|
|
1586
|
-
console.error('Federated: tryAutoLogin failed', err);
|
|
1593
|
+
// } catch (err) {
|
|
1594
|
+
// console.error('Federated: tryAutoLogin failed', err);
|
|
1587
1595
|
} finally {
|
|
1588
1596
|
state.initialized = true;
|
|
1589
1597
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Cookie from 'js-cookie';
|
|
2
2
|
import { getCookieOptions } from '@arcblock/ux/lib/Util';
|
|
3
|
+
import { debugTmp } from '../../utils';
|
|
3
4
|
|
|
4
5
|
export default class CookieStorageEngine {
|
|
5
6
|
constructor(storageKey, options) {
|
|
@@ -18,6 +19,7 @@ export default class CookieStorageEngine {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
removeToken() {
|
|
22
|
+
debugTmp('[CookieStorageEngine] removeToken');
|
|
21
23
|
return Cookie.remove(this.storageKey, getCookieOptions(this.options));
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jwtDecode from 'jwt-decode';
|
|
2
|
+
import { debugTmp } from '../../utils';
|
|
2
3
|
|
|
3
4
|
export default class LocalStorageEngine {
|
|
4
5
|
constructor(storageKey) {
|
|
@@ -46,6 +47,7 @@ export default class LocalStorageEngine {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
removeToken() {
|
|
50
|
+
debugTmp('[LocalStorageEngine] removeToken');
|
|
49
51
|
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
|
|
50
52
|
return undefined;
|
|
51
53
|
}
|
package/src/utils.js
CHANGED
|
@@ -18,6 +18,8 @@ import { NotOpenError } from './error';
|
|
|
18
18
|
const { version } = pkg;
|
|
19
19
|
|
|
20
20
|
export const debug = createDebug('did-connect');
|
|
21
|
+
export const debugTmp = createDebug('did-connect:tmp');
|
|
22
|
+
export const debugTmpInterval = createDebug('did-connect:tmp-interval');
|
|
21
23
|
export const logger = createLogger('did-connect');
|
|
22
24
|
|
|
23
25
|
export * from '@arcblock/ux/lib/Util/wallet';
|