@arcblock/did-connect-react 3.5.2 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/ConnectContext.d.ts +13 -0
  2. package/dist/ConnectContext.d.ts.map +1 -0
  3. package/dist/ConnectContext.js +14 -0
  4. package/dist/ConnectContext.js.map +1 -0
  5. package/dist/ConnectProvider.d.ts +11 -0
  6. package/dist/ConnectProvider.d.ts.map +1 -0
  7. package/dist/ConnectProvider.js +23 -0
  8. package/dist/ConnectProvider.js.map +1 -0
  9. package/dist/compat/SessionProvider.d.ts +22 -0
  10. package/dist/compat/SessionProvider.d.ts.map +1 -0
  11. package/dist/compat/SessionProvider.js +17 -0
  12. package/dist/compat/SessionProvider.js.map +1 -0
  13. package/dist/compat/index.d.ts +4 -0
  14. package/dist/compat/index.d.ts.map +1 -0
  15. package/dist/compat/index.js +3 -0
  16. package/dist/compat/index.js.map +1 -0
  17. package/dist/compat/useSessionContext.d.ts +14 -0
  18. package/dist/compat/useSessionContext.d.ts.map +1 -0
  19. package/dist/compat/useSessionContext.js +20 -0
  20. package/dist/compat/useSessionContext.js.map +1 -0
  21. package/dist/components/LoginPage.d.ts +15 -0
  22. package/dist/components/LoginPage.d.ts.map +1 -0
  23. package/dist/components/LoginPage.js +33 -0
  24. package/dist/components/LoginPage.js.map +1 -0
  25. package/dist/components/UserAvatar.d.ts +19 -0
  26. package/dist/components/UserAvatar.d.ts.map +1 -0
  27. package/dist/components/UserAvatar.js +45 -0
  28. package/dist/components/UserAvatar.js.map +1 -0
  29. package/dist/hooks/index.d.ts +11 -0
  30. package/dist/hooks/index.d.ts.map +1 -0
  31. package/dist/hooks/index.js +6 -0
  32. package/dist/hooks/index.js.map +1 -0
  33. package/dist/hooks/useConnect.d.ts +15 -0
  34. package/dist/hooks/useConnect.d.ts.map +1 -0
  35. package/dist/hooks/useConnect.js +19 -0
  36. package/dist/hooks/useConnect.js.map +1 -0
  37. package/dist/hooks/useEmail.d.ts +11 -0
  38. package/dist/hooks/useEmail.d.ts.map +1 -0
  39. package/dist/hooks/useEmail.js +47 -0
  40. package/dist/hooks/useEmail.js.map +1 -0
  41. package/dist/hooks/useOAuth.d.ts +12 -0
  42. package/dist/hooks/useOAuth.d.ts.map +1 -0
  43. package/dist/hooks/useOAuth.js +75 -0
  44. package/dist/hooks/useOAuth.js.map +1 -0
  45. package/dist/hooks/usePasskey.d.ts +14 -0
  46. package/dist/hooks/usePasskey.d.ts.map +1 -0
  47. package/dist/hooks/usePasskey.js +35 -0
  48. package/dist/hooks/usePasskey.js.map +1 -0
  49. package/dist/hooks/useSession.d.ts +12 -0
  50. package/dist/hooks/useSession.d.ts.map +1 -0
  51. package/dist/hooks/useSession.js +30 -0
  52. package/dist/hooks/useSession.js.map +1 -0
  53. package/dist/index.d.ts +13 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +11 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/internals/blocklet-config.d.ts +22 -0
  58. package/dist/internals/blocklet-config.d.ts.map +1 -0
  59. package/dist/internals/blocklet-config.js +26 -0
  60. package/dist/internals/blocklet-config.js.map +1 -0
  61. package/dist/internals/local-storage-adapter.d.ts +12 -0
  62. package/dist/internals/local-storage-adapter.d.ts.map +1 -0
  63. package/dist/internals/local-storage-adapter.js +32 -0
  64. package/dist/internals/local-storage-adapter.js.map +1 -0
  65. package/dist/internals/use-sync-state.d.ts +18 -0
  66. package/dist/internals/use-sync-state.d.ts.map +1 -0
  67. package/dist/internals/use-sync-state.js +38 -0
  68. package/dist/internals/use-sync-state.js.map +1 -0
  69. package/package.json +33 -79
  70. package/LICENSE +0 -13
  71. package/README.md +0 -134
  72. package/dist/standalone/did-connect-react.css +0 -1
  73. package/dist/standalone/index.js +0 -136774
  74. package/lib/Address/index.js +0 -4
  75. package/lib/Avatar/index.js +0 -4
  76. package/lib/Button/index.js +0 -17
  77. package/lib/Connect/assets/locale.js +0 -147
  78. package/lib/Connect/assets/login-bg.png +0 -0
  79. package/lib/Connect/assets/login-slogan.js +0 -9
  80. package/lib/Connect/components/action-button.js +0 -26
  81. package/lib/Connect/components/app-tips.js +0 -132
  82. package/lib/Connect/components/auto-height.js +0 -31
  83. package/lib/Connect/components/back-button.js +0 -25
  84. package/lib/Connect/components/connect-status.js +0 -263
  85. package/lib/Connect/components/did-connect-title.js +0 -127
  86. package/lib/Connect/components/download-tips.js +0 -52
  87. package/lib/Connect/components/loading.js +0 -26
  88. package/lib/Connect/components/login-item/connect-choose-list.js +0 -257
  89. package/lib/Connect/components/login-item/connect-provider-list.js +0 -345
  90. package/lib/Connect/components/login-item/login-method-item.js +0 -147
  91. package/lib/Connect/components/login-item/mobile-login-item.js +0 -116
  92. package/lib/Connect/components/login-item/passkey-login-item.js +0 -44
  93. package/lib/Connect/components/login-item/wallet-login-options.js +0 -114
  94. package/lib/Connect/components/login-item/web-login-item.js +0 -104
  95. package/lib/Connect/components/mask-overlay.js +0 -34
  96. package/lib/Connect/components/refresh-overlay.js +0 -57
  97. package/lib/Connect/components/switch-app.js +0 -70
  98. package/lib/Connect/connect.js +0 -505
  99. package/lib/Connect/contexts/state.js +0 -156
  100. package/lib/Connect/fallback-connect.js +0 -53
  101. package/lib/Connect/fullpage.js +0 -5
  102. package/lib/Connect/hooks/auth-url.js +0 -23
  103. package/lib/Connect/hooks/method-list.js +0 -46
  104. package/lib/Connect/hooks/page-show.js +0 -17
  105. package/lib/Connect/hooks/provider-list.js +0 -69
  106. package/lib/Connect/hooks/security.js +0 -27
  107. package/lib/Connect/hooks/token.js +0 -296
  108. package/lib/Connect/hooks/use-apps.js +0 -19
  109. package/lib/Connect/hooks/use-quick-connect.js +0 -86
  110. package/lib/Connect/index.js +0 -16
  111. package/lib/Connect/landing-page.js +0 -5
  112. package/lib/Connect/plugins/email/index.js +0 -65
  113. package/lib/Connect/plugins/email/list-item.js +0 -31
  114. package/lib/Connect/plugins/email/placeholder.js +0 -284
  115. package/lib/Connect/plugins/index.js +0 -4
  116. package/lib/Connect/use-connect.js +0 -164
  117. package/lib/Connect/with-blocklet.js +0 -15
  118. package/lib/Connect/with-bridge-call.js +0 -108
  119. package/lib/Federated/context.js +0 -61
  120. package/lib/Federated/index.js +0 -7
  121. package/lib/Logo/index.js +0 -4
  122. package/lib/OAuth/bind-conflict-alert.js +0 -29
  123. package/lib/OAuth/context.js +0 -277
  124. package/lib/OAuth/guest.svg.js +0 -5
  125. package/lib/OAuth/index.js +0 -7
  126. package/lib/OAuth/passport-switcher.js +0 -5
  127. package/lib/Passkey/actions.js +0 -170
  128. package/lib/Passkey/constants.js +0 -4
  129. package/lib/Passkey/context.js +0 -281
  130. package/lib/Passkey/dialog.js +0 -280
  131. package/lib/Passkey/icon.js +0 -13
  132. package/lib/Passkey/index.js +0 -9
  133. package/lib/Service/index.js +0 -62
  134. package/lib/Session/assets/did-spaces-guide-cover.svg.js +0 -111
  135. package/lib/Session/assets/did-spaces-guide-icon.svg.js +0 -9
  136. package/lib/Session/context.js +0 -5
  137. package/lib/Session/did-spaces-guide.js +0 -136
  138. package/lib/Session/handler.js +0 -55
  139. package/lib/Session/hooks/use-federated.js +0 -64
  140. package/lib/Session/hooks/use-mobile.js +0 -8
  141. package/lib/Session/hooks/use-protected-routes.js +0 -11
  142. package/lib/Session/hooks/use-session-token.js +0 -181
  143. package/lib/Session/hooks/use-verify.js +0 -45
  144. package/lib/Session/index.js +0 -941
  145. package/lib/Session/libs/constants.js +0 -18
  146. package/lib/Session/libs/did-spaces.js +0 -10
  147. package/lib/Session/libs/federated.js +0 -42
  148. package/lib/Session/libs/index.js +0 -15
  149. package/lib/Session/libs/locales.js +0 -161
  150. package/lib/Session/libs/login-mobile.js +0 -55
  151. package/lib/Session/window-focus-aware.js +0 -17
  152. package/lib/SessionManager/index.js +0 -4
  153. package/lib/Storage/engine/cookie.js +0 -22
  154. package/lib/Storage/engine/local-storage.js +0 -37
  155. package/lib/Storage/index.js +0 -23
  156. package/lib/User/index.js +0 -6
  157. package/lib/User/use-did.js +0 -59
  158. package/lib/User/wrap-did.js +0 -13
  159. package/lib/WebWalletSWKeeper/index.js +0 -5
  160. package/lib/components/PassportSwitcher.js +0 -128
  161. package/lib/constant.js +0 -23
  162. package/lib/error.js +0 -8
  163. package/lib/hooks/use-locale.js +0 -7
  164. package/lib/index.js +0 -111
  165. package/lib/locales/en.js +0 -17
  166. package/lib/locales/index.js +0 -10
  167. package/lib/locales/zh.js +0 -17
  168. package/lib/node_modules/@blocklet/js-sdk/dist/index.js +0 -512
  169. package/lib/packages/did-connect/package.json.js +0 -7
  170. package/lib/types.d.ts +0 -355
  171. package/lib/utils.js +0 -225
package/lib/types.d.ts DELETED
@@ -1,355 +0,0 @@
1
- import type { AxiosInstance } from 'axios';
2
- import type { EventEmitter } from 'eventemitter3';
3
- import { DEFAULT_TIMEOUT } from './constant';
4
- import type { ReactNode } from 'react';
5
-
6
- export type ConnectMessages = {
7
- title: string;
8
- scan: string;
9
- success: ReactNode;
10
- confirm?: string; // 貌似没有地方使用,先设置为非必填
11
- error?: string;
12
- };
13
-
14
- // FIXME: @zhanghan 将来需要改成 ts,直接从常量值 LOGIN_PROVIDER 中提取类型,目前只能写成这样
15
- export type WalletProvider = 'wallet' | 'auth0' | 'apple' | 'github' | 'google' | 'passkey';
16
-
17
- export type WalletOS = 'web' | 'android' | 'ios' | '';
18
- export type UserRole = 'guest' | 'member' | 'admin' | 'owner' | string;
19
- export type BaseLocale = 'en' | 'zh';
20
- export type UserLocale = BaseLocale | string;
21
-
22
- export type ConnectProps = {
23
- /**
24
- * @example login
25
- */
26
- action: string;
27
- containerEl?: Element;
28
- /**
29
- * @default "/api/did"
30
- */
31
- prefix?: string;
32
- /**
33
- * @default "en"
34
- */
35
- locale?: 'en' | 'zh';
36
- /**
37
- * @default false
38
- */
39
- popup?: boolean;
40
- /**
41
- * @default 2*1000
42
- */
43
- checkInterval?: number;
44
- /**
45
- * @default 5*60*1000
46
- */
47
- checkTimeout?: number;
48
- /**
49
- * @default 2*1000
50
- */
51
- closeTimeout?: number;
52
- /**
53
- * @default {}
54
- */
55
- extraParams?: object;
56
- /**
57
- * @default "_t_"
58
- */
59
- tokenKey?: string;
60
- /**
61
- * @default "_ek_"
62
- */
63
- encKey?: string;
64
- /**
65
- * @default "''"
66
- */
67
- baseUrl?: string;
68
- /**
69
- * @default {
70
- title: 'DID Connect',
71
- scan: 'Scan QR code to complete this action',
72
- confirm: 'Confirm on your DID Wallet',
73
- success: 'Success!'
74
- }
75
- */
76
- messages?: ConnectMessages;
77
- /**
78
- * @default true
79
- */
80
- autoConnect?: boolean;
81
- /**
82
- * @default true
83
- */
84
- forceConnected?: boolean | string;
85
- /**
86
- * @default true
87
- */
88
- saveConnect?: boolean;
89
- /**
90
- * @default true
91
- */
92
- useSocket?: boolean;
93
- /**
94
- * @default true
95
- */
96
- allowWallet?: boolean;
97
- /**
98
- * @default true
99
- */
100
- passkeyBehavior?: 'none' | 'both' | 'only-existing' | 'only-new';
101
- /**
102
- * @default "wallet"
103
- */
104
- provider?: 'wallet' | 'auth0' | '';
105
- /**
106
- * @default 160
107
- */
108
- qrcodeSize?: number;
109
- /**
110
- * @default true
111
- */
112
- showDownload?: boolean;
113
- /**
114
- * @default "https://web.abtwallet.io"
115
- */
116
- webWalletUrl?: string;
117
- /**
118
- * @default ["web", "mobile", "github", "apple", "google", "auth0", "passkey"]
119
- */
120
- enabledConnectTypes?: Array<'web' | 'mobile' | 'auth0', 'github' | 'apple' | 'google' | 'passkey'>;
121
- extraContent?: any;
122
- loadingEle?: any;
123
- /**
124
- * @default false
125
- */
126
- disableSwitchApp?: boolean;
127
- /**
128
- * @default false
129
- */
130
- hideCloseButton?: boolean;
131
- /**
132
- * @default {}
133
- */
134
- options?: {
135
- /**
136
- * @default true
137
- */
138
- showQuickConnect?: boolean;
139
- };
140
- onRecreateSession?: Function;
141
- checkFn?: () => boolean;
142
- onSuccess?: (result: object) => void;
143
- onError?: (error: any) => void;
144
- onClose?: Function;
145
- };
146
-
147
- export type OpenConnect = (params: ConnectProps) => void;
148
- export type OpenConnectPopup = (
149
- params: ConnectProps,
150
- options?: {
151
- baseUrl?: string;
152
- locale?: BaseLocale;
153
- }
154
- ) => void;
155
-
156
- export type OpenDidConnect = (
157
- params: ConnectProps,
158
- options?: {
159
- /**
160
- * 打开 DID Connect 的模式
161
- * @default 'popup'
162
- */
163
- openMode?: 'redirect' | 'window' | 'popup';
164
- requirements?: {
165
- /**
166
- * 是否要求登录
167
- * @default true
168
- */
169
- login?: boolean;
170
- /**
171
- * 是否要求绑定 DID Wallet 账户
172
- * @default true
173
- */
174
- bindWallet?: boolean;
175
- /**
176
- * 是否要求绑定 DID Spaces
177
- * @default false
178
- */
179
- bindDidSpaces?: false | 'read' | 'full';
180
- // bindOAuth?: boolea // 暂不支持,这里要配置的情况会稍微复杂一些
181
- };
182
- baseUrl?: string;
183
- locale?: BaseLocale;
184
- }
185
- ) => void;
186
-
187
- export type CloseConnect = Function;
188
-
189
- export type CommonSessionFn = (done?: Function, params?: object) => void;
190
-
191
- export type LoginSessionFn = (
192
- done?: Function,
193
- params?: {
194
- openMode: 'redirect' | 'window'; // iframe: 暂未启用
195
- provider?: 'wallet';
196
- redirect?: string;
197
- forceConnected?: string;
198
- sourceAppPid?: string;
199
- passkeyBehavior?: string;
200
- [key: string]: any;
201
- },
202
- origin?: string
203
- ) => any;
204
-
205
- export type LogoutSessionFn = (done?: Function) => void;
206
-
207
- export type Passport = {
208
- id: string;
209
- name: string;
210
- title: string;
211
- role: UserRole;
212
- };
213
- export type ConnectAccount = {
214
- provider: WalletProvider;
215
- did: string;
216
- pk: string;
217
- id?: string;
218
- firstLoginAt?: string;
219
- lastLoginAt?: string;
220
- lastLoginIp?: string;
221
- };
222
-
223
- export type SessionUser = {
224
- avatar: string;
225
- did: string;
226
- email: string;
227
- fullName: string;
228
- remark?: string;
229
- role?: UserRole;
230
- sourceAppPid: null | string;
231
- sourceProvider: WalletProvider;
232
- };
233
-
234
- export type UserSession = {
235
- id: string;
236
- appName: string;
237
- appPid: string;
238
- updatedAt: string;
239
- userDid: string;
240
- visitorId: string;
241
- extra: object;
242
- user: SessionUser;
243
- passportId?: string;
244
- };
245
-
246
- export type User = {
247
- approved: boolean;
248
- avatar: string;
249
- connectedAccounts: ConnectAccount[];
250
- did: string;
251
- pk: string;
252
- email: string;
253
- fullName: string;
254
- role: UserRole;
255
- locale: UserLocale;
256
- passports: Passport[];
257
- permissions: any[];
258
- sourceAppPid?: string;
259
- sourceProvider?: WalletProvider;
260
- didSpace?: object;
261
- remark?: string;
262
- createdAt: string;
263
- updatedAt: string;
264
- firstLoginAt?: string;
265
- lastLoginAt?: string;
266
- lastLoginIp?: string;
267
- };
268
-
269
- export type SessionProps = {
270
- action: string;
271
- error: string;
272
- initialized: boolean;
273
- loading: boolean;
274
- open: boolean;
275
- walletOS: WalletOS;
276
- user?: User;
277
- locale: UserLocale;
278
- provider?: WalletProvider;
279
- baseUrl?: string;
280
- federatedMaster?: object;
281
- login: LoginSessionFn;
282
- logout: LogoutSessionFn;
283
- switch: Function;
284
- switchDid: CommonSessionFn;
285
- autoSwitchDid: Function;
286
- switchProfile: CommonSessionFn;
287
- switchPassport: CommonSessionFn;
288
- bindWallet: CommonSessionFn;
289
- refresh: Function;
290
- updateConnectedInfo: (data: object) => void;
291
- openDidConnect: OpenDidConnect;
292
-
293
- useOAuth: Function;
294
- OAuthProvider: Function;
295
- OAuthConsumer: Function;
296
- OAuthContext: object;
297
-
298
- usePasskey: Function;
299
- PasskeyProvider: Function;
300
- PasskeyConsumer: Function;
301
- PasskeyContext: object;
302
-
303
- useDid: (options: { session: Session }) => void;
304
- WrapDid: Function;
305
- getUserSessions: () => Promise<UserSession[]>;
306
- };
307
-
308
- export type SessionStorageProps = {
309
- getToken: Function;
310
- setToken: Function;
311
- removeToken: Function;
312
- };
313
-
314
- export type SessionContext = {
315
- api: AxiosInstance; // api 实例(axios)
316
- events: EventEmitter; // session 事件订阅器
317
- storage: SessionStorageProps; // sessionToken 的存储实例
318
- session: SessionProps; // session 实例
319
- connectApi: {
320
- open: OpenConnect;
321
- close: CloseConnect;
322
- }; // use-connect 的 connectApi
323
- };
324
-
325
- export interface TokenState {
326
- checking: boolean;
327
- loading: boolean;
328
- token: string;
329
- url: string;
330
- store: object;
331
- status: 'created' | 'scanned' | 'succeed' | 'error' | 'timeout' | 'busy' | 'forbidden';
332
- error: string;
333
- checkCount: number;
334
- mfaCode?: number;
335
- appInfo: object;
336
- memberAppInfo: object;
337
- connectedDid: string;
338
- saveConnect: boolean;
339
- inExistingSession: boolean;
340
- nextWorkflow?: string;
341
- baseUrl: string;
342
- prefix: string;
343
- extraParams: object;
344
- checkFn: Function;
345
- results: object;
346
- action: string;
347
- provider: 'wallet' | 'auth0' | 'apple' | 'github' | 'google';
348
- }
349
-
350
- export type SwitchBehavior = 'auto' | 'disabled' | 'required';
351
- export type DIDConnectUrlOptions = {
352
- switchBehavior: SwitchBehavior;
353
- sourceAppPid: string;
354
- forceConnected: boolean | string;
355
- };
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 "./node_modules/@blocklet/js-sdk/dist/index.js";
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 "./packages/did-connect/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
- };