@arcblock/did-connect-react 3.4.15 → 3.5.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 (198) hide show
  1. package/dist/standalone/did-connect-react.css +1 -0
  2. package/dist/standalone/index.js +133700 -0
  3. package/lib/package.json.js +1 -1
  4. package/package.json +11 -6
  5. package/.aigne/doc-smith/config.yaml +0 -85
  6. package/.aigne/doc-smith/history.yaml +0 -6
  7. package/.aigne/doc-smith/output/structure-plan.json +0 -204
  8. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  9. package/.aigne/doc-smith/upload-cache.yaml +0 -213
  10. package/docs/_sidebar.md +0 -18
  11. package/docs/advanced-authentication-methods.ja.md +0 -261
  12. package/docs/advanced-authentication-methods.md +0 -261
  13. package/docs/advanced-authentication-methods.zh-TW.md +0 -261
  14. package/docs/advanced-authentication-methods.zh.md +0 -261
  15. package/docs/advanced-utilities.ja.md +0 -132
  16. package/docs/advanced-utilities.md +0 -132
  17. package/docs/advanced-utilities.zh-TW.md +0 -132
  18. package/docs/advanced-utilities.zh.md +0 -132
  19. package/docs/advanced.ja.md +0 -95
  20. package/docs/advanced.md +0 -95
  21. package/docs/advanced.zh-TW.md +0 -95
  22. package/docs/advanced.zh.md +0 -95
  23. package/docs/api-reference.ja.md +0 -178
  24. package/docs/api-reference.md +0 -178
  25. package/docs/api-reference.zh-TW.md +0 -178
  26. package/docs/api-reference.zh.md +0 -178
  27. package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
  28. package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
  29. package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
  30. package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
  31. package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
  32. package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
  33. package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
  34. package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
  35. package/docs/assets/diagram/overview-01.ja.jpg +0 -0
  36. package/docs/assets/diagram/overview-01.jpg +0 -0
  37. package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
  38. package/docs/assets/diagram/overview-01.zh.jpg +0 -0
  39. package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
  40. package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
  41. package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
  42. package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
  43. package/docs/core-components-did-connect.ja.md +0 -166
  44. package/docs/core-components-did-connect.md +0 -166
  45. package/docs/core-components-did-connect.zh-TW.md +0 -166
  46. package/docs/core-components-did-connect.zh.md +0 -166
  47. package/docs/core-components-session-provider.ja.md +0 -197
  48. package/docs/core-components-session-provider.md +0 -197
  49. package/docs/core-components-session-provider.zh-TW.md +0 -197
  50. package/docs/core-components-session-provider.zh.md +0 -197
  51. package/docs/core-components.ja.md +0 -16
  52. package/docs/core-components.md +0 -16
  53. package/docs/core-components.zh-TW.md +0 -16
  54. package/docs/core-components.zh.md +0 -16
  55. package/docs/getting-started.ja.md +0 -138
  56. package/docs/getting-started.md +0 -138
  57. package/docs/getting-started.zh-TW.md +0 -138
  58. package/docs/getting-started.zh.md +0 -138
  59. package/docs/hooks-use-connect.ja.md +0 -178
  60. package/docs/hooks-use-connect.md +0 -178
  61. package/docs/hooks-use-connect.zh-TW.md +0 -178
  62. package/docs/hooks-use-connect.zh.md +0 -178
  63. package/docs/hooks-use-did.ja.md +0 -107
  64. package/docs/hooks-use-did.md +0 -107
  65. package/docs/hooks-use-did.zh-TW.md +0 -107
  66. package/docs/hooks-use-did.zh.md +0 -107
  67. package/docs/hooks-use-oauth-passkey.ja.md +0 -188
  68. package/docs/hooks-use-oauth-passkey.md +0 -188
  69. package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
  70. package/docs/hooks-use-oauth-passkey.zh.md +0 -188
  71. package/docs/hooks.ja.md +0 -23
  72. package/docs/hooks.md +0 -23
  73. package/docs/hooks.zh-TW.md +0 -23
  74. package/docs/hooks.zh.md +0 -23
  75. package/docs/overview.ja.md +0 -119
  76. package/docs/overview.md +0 -119
  77. package/docs/overview.zh-TW.md +0 -119
  78. package/docs/overview.zh.md +0 -119
  79. package/docs/ui-components-address.ja.md +0 -121
  80. package/docs/ui-components-address.md +0 -121
  81. package/docs/ui-components-address.zh-TW.md +0 -121
  82. package/docs/ui-components-address.zh.md +0 -121
  83. package/docs/ui-components-avatar.ja.md +0 -65
  84. package/docs/ui-components-avatar.md +0 -65
  85. package/docs/ui-components-avatar.zh-TW.md +0 -65
  86. package/docs/ui-components-avatar.zh.md +0 -65
  87. package/docs/ui-components-button.ja.md +0 -99
  88. package/docs/ui-components-button.md +0 -99
  89. package/docs/ui-components-button.zh-TW.md +0 -99
  90. package/docs/ui-components-button.zh.md +0 -99
  91. package/docs/ui-components-logo.ja.md +0 -52
  92. package/docs/ui-components-logo.md +0 -52
  93. package/docs/ui-components-logo.zh-TW.md +0 -52
  94. package/docs/ui-components-logo.zh.md +0 -52
  95. package/docs/ui-components.ja.md +0 -57
  96. package/docs/ui-components.md +0 -57
  97. package/docs/ui-components.zh-TW.md +0 -57
  98. package/docs/ui-components.zh.md +0 -57
  99. package/glossary.md +0 -1
  100. package/src/Address/index.jsx +0 -2
  101. package/src/Avatar/index.jsx +0 -2
  102. package/src/Button/Button.stories.jsx +0 -7
  103. package/src/Button/index.jsx +0 -21
  104. package/src/Connect/Connect.stories.jsx +0 -34
  105. package/src/Connect/assets/locale.js +0 -149
  106. package/src/Connect/assets/login-bg.png +0 -0
  107. package/src/Connect/assets/login-slogan.js +0 -7
  108. package/src/Connect/components/action-button.jsx +0 -22
  109. package/src/Connect/components/app-tips.jsx +0 -156
  110. package/src/Connect/components/auto-height.jsx +0 -38
  111. package/src/Connect/components/back-button.jsx +0 -24
  112. package/src/Connect/components/connect-status.jsx +0 -259
  113. package/src/Connect/components/did-connect-title.jsx +0 -107
  114. package/src/Connect/components/download-tips.jsx +0 -55
  115. package/src/Connect/components/loading.jsx +0 -25
  116. package/src/Connect/components/login-item/connect-choose-list.jsx +0 -328
  117. package/src/Connect/components/login-item/connect-provider-list.jsx +0 -473
  118. package/src/Connect/components/login-item/login-method-item.jsx +0 -139
  119. package/src/Connect/components/login-item/mobile-login-item.jsx +0 -184
  120. package/src/Connect/components/login-item/passkey-login-item.jsx +0 -56
  121. package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
  122. package/src/Connect/components/login-item/web-login-item.jsx +0 -159
  123. package/src/Connect/components/mask-overlay.jsx +0 -32
  124. package/src/Connect/components/refresh-overlay.jsx +0 -52
  125. package/src/Connect/components/switch-app.jsx +0 -69
  126. package/src/Connect/connect.jsx +0 -635
  127. package/src/Connect/contexts/state.jsx +0 -235
  128. package/src/Connect/fallback-connect.jsx +0 -47
  129. package/src/Connect/fullpage.jsx +0 -3
  130. package/src/Connect/hooks/auth-url.js +0 -31
  131. package/src/Connect/hooks/method-list.js +0 -121
  132. package/src/Connect/hooks/page-show.js +0 -24
  133. package/src/Connect/hooks/provider-list.js +0 -168
  134. package/src/Connect/hooks/security.js +0 -40
  135. package/src/Connect/hooks/token.js +0 -627
  136. package/src/Connect/hooks/use-apps.js +0 -69
  137. package/src/Connect/hooks/use-quick-connect.js +0 -119
  138. package/src/Connect/index.jsx +0 -21
  139. package/src/Connect/landing-page.jsx +0 -3
  140. package/src/Connect/plugins/email/index.jsx +0 -85
  141. package/src/Connect/plugins/email/list-item.jsx +0 -35
  142. package/src/Connect/plugins/email/placeholder.jsx +0 -372
  143. package/src/Connect/plugins/index.js +0 -2
  144. package/src/Connect/use-connect.jsx +0 -321
  145. package/src/Connect/with-blocklet.jsx +0 -26
  146. package/src/Connect/with-bridge-call.jsx +0 -138
  147. package/src/Federated/context.jsx +0 -93
  148. package/src/Federated/index.jsx +0 -1
  149. package/src/Logo/index.jsx +0 -2
  150. package/src/OAuth/bind-conflict-alert.jsx +0 -37
  151. package/src/OAuth/context.jsx +0 -407
  152. package/src/OAuth/guest.svg +0 -20
  153. package/src/OAuth/index.jsx +0 -1
  154. package/src/OAuth/passport-switcher.jsx +0 -2
  155. package/src/Passkey/actions.jsx +0 -217
  156. package/src/Passkey/constants.js +0 -2
  157. package/src/Passkey/context.jsx +0 -395
  158. package/src/Passkey/dialog.jsx +0 -401
  159. package/src/Passkey/icon.jsx +0 -10
  160. package/src/Passkey/index.jsx +0 -2
  161. package/src/Service/index.jsx +0 -96
  162. package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
  163. package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
  164. package/src/Session/context.jsx +0 -7
  165. package/src/Session/did-spaces-guide.jsx +0 -173
  166. package/src/Session/handler.jsx +0 -98
  167. package/src/Session/hooks/use-federated.js +0 -91
  168. package/src/Session/hooks/use-mobile.jsx +0 -6
  169. package/src/Session/hooks/use-protected-routes.js +0 -16
  170. package/src/Session/hooks/use-session-token.js +0 -400
  171. package/src/Session/hooks/use-verify.jsx +0 -76
  172. package/src/Session/index.jsx +0 -1789
  173. package/src/Session/libs/constants.js +0 -17
  174. package/src/Session/libs/did-spaces.js +0 -38
  175. package/src/Session/libs/federated.js +0 -82
  176. package/src/Session/libs/index.js +0 -5
  177. package/src/Session/libs/locales.js +0 -160
  178. package/src/Session/libs/login-mobile.js +0 -80
  179. package/src/Session/window-focus-aware.jsx +0 -28
  180. package/src/SessionManager/index.jsx +0 -2
  181. package/src/Storage/engine/cookie.js +0 -25
  182. package/src/Storage/engine/local-storage.js +0 -57
  183. package/src/Storage/index.js +0 -25
  184. package/src/User/index.js +0 -4
  185. package/src/User/use-did.js +0 -80
  186. package/src/User/wrap-did.jsx +0 -18
  187. package/src/WebWalletSWKeeper/index.jsx +0 -3
  188. package/src/components/PassportSwitcher.jsx +0 -160
  189. package/src/constant.js +0 -27
  190. package/src/error.js +0 -6
  191. package/src/hooks/use-locale.jsx +0 -6
  192. package/src/index.js +0 -32
  193. package/src/locales/en.jsx +0 -15
  194. package/src/locales/index.jsx +0 -13
  195. package/src/locales/zh.jsx +0 -15
  196. package/src/types.d.ts +0 -355
  197. package/src/utils.js +0 -413
  198. package/vite.config.mjs +0 -29
@@ -1,17 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
-
3
- export const EVENTS = {
4
- LOGIN: Symbol('login'),
5
- LOGIN_FAILED: Symbol('loginFailed'),
6
- CANCEL_LOGIN: Symbol('cancelLogin'),
7
- LOGOUT: Symbol('logout'),
8
- SWITCH_PROFILE: Symbol('switchProfile'),
9
- CANCEL_SWITCH_PROFILE: Symbol('cancelSwitchProfile'),
10
- SWITCH_PASSPORT: Symbol('switchPassport'),
11
- SWITCH_PASSPORT_FAILED: Symbol('switchPassportFailed'),
12
- CANCEL_SWITCH_PASSPORT: Symbol('cancelSwitchPassport'),
13
- BIND_WALLET: Symbol('bindWallet'),
14
- BIND_WALLET_FAILED: Symbol('bindWalletFailed'),
15
- CANCEL_BIND_WALLET: Symbol('cancelBindWallet'),
16
- DID_SPACE_CONNECTED: Symbol('didSpaceConnected'),
17
- };
@@ -1,38 +0,0 @@
1
- /* eslint-disable require-await */
2
- /* eslint-disable import/prefer-default-export */
3
-
4
- import { BLOCKLET_SERVICE_PATH_PREFIX, DID_SPACES_BASE_URL } from '../../constant';
5
-
6
- /**
7
- * @description
8
- * @export
9
- * @param {*} user
10
- * @return {Promise<boolean>}
11
- */
12
- export async function didSpacesIsRequired(user) {
13
- if (user?.didSpace?.endpoint) {
14
- return false;
15
- }
16
-
17
- if (!window.blocklet) {
18
- return false;
19
- }
20
-
21
- // 如果是在 iframe 中,直接返回 false
22
- if (window.self !== window.top) {
23
- return false;
24
- }
25
-
26
- if (window.location.origin === new URL(DID_SPACES_BASE_URL).origin) {
27
- return false;
28
- }
29
-
30
- // @note: 如果在 blocklet service 页面中,那么默认不展示 did-spaces 引导
31
- if (window.location.href.includes(BLOCKLET_SERVICE_PATH_PREFIX)) {
32
- return false;
33
- }
34
-
35
- const { componentMountPoints } = window.blocklet;
36
- const [, componentDid] = window.blocklet.componentId.split('/');
37
- return componentMountPoints.some((c) => c?.capabilities?.didSpace === 'requiredOnConnect' && componentDid === c.did);
38
- }
@@ -1,82 +0,0 @@
1
- import { joinURL } from 'ufo';
2
- import { getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
3
-
4
- import { createAxios, sleep } from '../../utils';
5
- import { BLOCKLET_SERVICE_PATH_PREFIX } from '../../constant';
6
-
7
- const api = createAxios();
8
-
9
- /**
10
- * 获取 master 的 token
11
- * @returns {Promise<{sessionToken: string; refreshToken: string;}>}
12
- */
13
- async function getMasterToken() {
14
- const url = joinURL(BLOCKLET_SERVICE_PATH_PREFIX, '/api/federated/loginMaster');
15
- const { data } = await api.post(url);
16
- return data;
17
- }
18
-
19
- // eslint-disable-next-line require-await
20
- export async function mountFederatedIframe({ mode, refreshToken = '', blocklet }) {
21
- const master = getMaster(blocklet);
22
- return new Promise((resolve) => {
23
- if (!['login', 'logout'].includes(mode)) {
24
- resolve();
25
- return;
26
- }
27
-
28
- const iframe = document.createElement('iframe');
29
- iframe.style.display = 'none';
30
- iframe.onload = async () => {
31
- // HACK: 即使当前页面已经 Load 成功,也强制等待 500ms,确保不会产生边缘情况的问题
32
- await sleep(500);
33
- document.body.removeChild(iframe);
34
- resolve();
35
- };
36
- iframe.src = joinURL(
37
- master.appUrl,
38
- BLOCKLET_SERVICE_PATH_PREFIX,
39
- `functional/federated?mode=${mode}&refreshToken=${refreshToken}`
40
- );
41
- document.body.appendChild(iframe);
42
- });
43
- }
44
-
45
- /**
46
- * @deprecated no longer used
47
- */
48
- export async function loginFederatedMaster(params = {}, { fetchToken = true, blocklet } = {}) {
49
- const enableFederated = getFederatedEnabled();
50
- if (!enableFederated) {
51
- console.warn('Federated not enabled');
52
- return null;
53
- }
54
- /**
55
- * @type {string}
56
- */
57
- let sessionToken;
58
- /**
59
- * @type {string}
60
- */
61
- let refreshToken;
62
-
63
- if (fetchToken) {
64
- ({ sessionToken, refreshToken } = await getMasterToken());
65
- }
66
-
67
- const master = getMaster(blocklet);
68
- const url = joinURL(master.appUrl, BLOCKLET_SERVICE_PATH_PREFIX, '/api/federated/login');
69
- const options = { withCredentials: true };
70
-
71
- if (sessionToken) {
72
- options.headers = {
73
- Authorization: `Bearer ${sessionToken}`,
74
- };
75
- }
76
-
77
- const { data } = await api.post(url, params, options);
78
- if (refreshToken) {
79
- await mountFederatedIframe({ mode: 'login', refreshToken, blocklet });
80
- }
81
- return data;
82
- }
@@ -1,5 +0,0 @@
1
- export * from './constants.js';
2
- export * from './did-spaces.js';
3
- export * from './federated.js';
4
- export * from './locales.js';
5
- export * from './login-mobile.js';
@@ -1,160 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- export const translations = {
3
- login: {
4
- en: {
5
- title: 'Login',
6
- scan: 'Login with one of the following methods',
7
- confirm: 'Confirm connection in your DID Wallet',
8
- success: 'Successfully logged in',
9
- },
10
- zh: {
11
- title: '登录',
12
- scan: '请使用下面的方式完成登录',
13
- confirm: '在 DID Wallet 中确认连接',
14
- success: '登录成功',
15
- },
16
- },
17
- 'switch-specified-did': {
18
- en: {
19
- title: 'Switch Account',
20
- scan: 'You need switch DID to {did} to complete the following actions',
21
- confirm: 'Confirm switch in your DID Wallet',
22
- success: 'Successfully switched',
23
- },
24
- zh: {
25
- title: '切换账号',
26
- scan: '你需要切换账号至 {did} 才能完成后续的操作',
27
- confirm: '在 DID Wallet 中确认切换',
28
- success: '切换成功',
29
- },
30
- },
31
- 'switch-did': {
32
- en: {
33
- title: 'Add Account',
34
- scan: 'Please use the following methods to add a new account',
35
- confirm: 'Confirm switch in your DID Wallet',
36
- success: 'Successfully added',
37
- },
38
- zh: {
39
- title: '添加账号',
40
- scan: '请使用下列方式添加新的账号',
41
- confirm: '在 DID Wallet 中确认切换',
42
- success: '添加成功',
43
- },
44
- },
45
- 'switch-profile': {
46
- en: {
47
- title: 'Switch Profile',
48
- scan: 'Use DID Wallet to switch profile',
49
- confirm: 'Select profile in your DID Wallet',
50
- success: 'Profile updated',
51
- },
52
- zh: {
53
- title: '切换个人信息',
54
- scan: '请使用 DID Wallet 来切换个人信息',
55
- confirm: '在 DID Wallet 中选择个人信息',
56
- success: '个人信息已经更新',
57
- },
58
- },
59
- 'switch-passport': {
60
- en: {
61
- title: 'Switch Passport',
62
- scan: 'Use DID Wallet to switch passport',
63
- confirm: 'Select passport in your DID Wallet',
64
- success: 'Passport and session updated',
65
- },
66
- zh: {
67
- title: '切换通行证',
68
- scan: '请使用 DID Wallet 来切换通行证',
69
- confirm: '在 DID Wallet 中选择通行证',
70
- success: '通行证和会话已经更新',
71
- },
72
- },
73
- 'connect-to-did-spaces-for-user': {
74
- en: {
75
- title: 'Please authorize the application to connect to your DID Space',
76
- scan: 'Please use your DID wallet to complete this authorization',
77
- confirm: 'Select the DID Spaces NFT in your DID wallet',
78
- success: 'Connection successful',
79
- },
80
- zh: {
81
- title: '请授权应用连接你的 DID Space',
82
- scan: '请使用 DID Wallet 来完成授权',
83
- confirm: '在 DID Wallet 中选择 DID Spaces NFT',
84
- success: '连接成功',
85
- },
86
- },
87
- 'bind-wallet': {
88
- en: {
89
- title: 'Connect DID Wallet for enhanced security',
90
- scan: 'Use DID Wallet to connect your account',
91
- success: 'Successfully connected',
92
- },
93
- zh: {
94
- title: '连接 DID Wallet 获得更高的安全性',
95
- scan: '请使用 DID Wallet 来连接您的账户',
96
- success: '连接成功',
97
- },
98
- },
99
- exchangePassport: {
100
- en: {
101
- action: 'Exchange Passport with NFT',
102
- tooltip: 'Exchange passport if you owns any required NFT',
103
- },
104
- zh: {
105
- action: '兑换通行证',
106
- tooltip: '通过出示你持有的特定 NFT 来获取通行证',
107
- },
108
- },
109
- lostPassport: {
110
- en: {
111
- action: 'Lost Passport',
112
- },
113
- zh: {
114
- action: '找回通行证',
115
- },
116
- },
117
-
118
- switchAccountDialog: {
119
- en: {
120
- confirm: 'Switch',
121
- title: 'Switch Account',
122
- description: 'Please switch accounts to complete next action',
123
- currentAccount: 'Current account',
124
- nextAccount: 'Account to be switched',
125
- },
126
- zh: {
127
- confirm: '切换',
128
- title: '切换账号',
129
- description: '请切换账号来完成后续的操作',
130
- currentAccount: '当前登录的账户',
131
- nextAccount: '即将切换的账户',
132
- },
133
- },
134
- verify: {
135
- zh: {
136
- title: '验证所有权',
137
- verify: '验证',
138
- reconnect: '换个应用',
139
- scan: '使用以下方法证明所有权',
140
- confirm: '请在钱包中确认签名,以允许服务器下载并解密备份',
141
- success: '所有权验证成功,正在进行还原',
142
- exists: '相同 DID 的应用已存在此节点上,没有继续恢复',
143
- open: '访问此应用',
144
- overwrite: '覆盖安装',
145
- abort: '访问验证已终止',
146
- },
147
- en: {
148
- title: 'Verify Ownership',
149
- verify: 'Verify',
150
- reconnect: 'Try another blocklet',
151
- scan: 'Use the following methods to prove ownership',
152
- confirm: 'Sign delegation to allow server to download and decrypt the backup',
153
- success: 'Ownership verified, the restoring is in progress',
154
- exists: 'This blocklet already exists on this server and restore is aborted',
155
- open: 'Visit Blocklet',
156
- overwrite: 'Overwrite',
157
- abort: 'Access verification aborted',
158
- },
159
- },
160
- };
@@ -1,80 +0,0 @@
1
- import { getApps } from '@arcblock/ux/lib/Util/federated';
2
- import { isUrl } from '@arcblock/ux/lib/Util';
3
- import { joinURL, withQuery } from 'ufo';
4
- import semver from 'semver';
5
- import bridge from '@arcblock/bridge';
6
- import pathToRegexp from 'path-to-regexp';
7
-
8
- import { BLOCKLET_SERVICE_PATH_PREFIX } from '../../constant';
9
- import { logger } from '../../utils';
10
-
11
- const BLACK_LIST = [
12
- `${BLOCKLET_SERVICE_PATH_PREFIX}/connect`,
13
- `${BLOCKLET_SERVICE_PATH_PREFIX}/login`,
14
- `${BLOCKLET_SERVICE_PATH_PREFIX}/invite`,
15
- `${BLOCKLET_SERVICE_PATH_PREFIX}/issue-passport`,
16
- `${BLOCKLET_SERVICE_PATH_PREFIX}/oauth/*`,
17
- ];
18
-
19
- const blackListRoute = BLACK_LIST.map((item) => pathToRegexp(item, []));
20
-
21
- export async function login() {
22
- const blocklet = window?.blocklet || {};
23
- const currentPath = window.location.pathname;
24
- const { componentId, CHAIN_TYPE: chainType = 'arcblock', appPid } = blocklet;
25
- const matched = blackListRoute.some((item) => item.exec(currentPath));
26
- if (matched) {
27
- return null;
28
- }
29
-
30
- const apps = getApps();
31
-
32
- try {
33
- // eth 多个地址和统一登录该如何组合?
34
- // member 的 url
35
- const searchParams = new URLSearchParams(window.location.search);
36
- const inviter = searchParams.get('inviter') || localStorage.getItem('inviter');
37
- const target = withQuery(joinURL(window.location.origin, BLOCKLET_SERVICE_PATH_PREFIX, '/api/user/loginByWallet'), {
38
- inviter,
39
- });
40
- const data = await bridge.asyncCall('arcLogin', {
41
- target,
42
- chainType,
43
- appPid,
44
- componentId,
45
- apps: apps.map((x) => {
46
- let appLogo = x?.appLogo;
47
- if (!isUrl(appLogo)) {
48
- appLogo = joinURL(x.appUrl, appLogo);
49
- }
50
- return {
51
- appName: x.appName,
52
- appPid: x.appPid,
53
- appUrl: x.appUrl,
54
- appLogo,
55
- sourceAppPid: x.sourceAppPid,
56
- };
57
- }),
58
- });
59
- return data;
60
- } catch (err) {
61
- logger.error('Failed login mobile', err);
62
- return null;
63
- }
64
- }
65
-
66
- export async function getMobileVisitorId() {
67
- const result = await bridge.asyncCall('arcGetVisitorId');
68
- return result;
69
- }
70
-
71
- export function checkEnableAutoLogin({ platform, version } = {}) {
72
- if (platform === 'ios' && version && semver.gte(version, '4.15.6')) {
73
- return true;
74
- }
75
- if (platform === 'android' && version && semver.gte(version, '4.15.1')) {
76
- return true;
77
- }
78
-
79
- return false;
80
- }
@@ -1,28 +0,0 @@
1
- import { useEffect } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useMemoizedFn, useDebounceFn } from 'ahooks';
4
-
5
- function WindowFocusAware({ callback }) {
6
- const debounceFn = useDebounceFn(callback);
7
- const handleVisibilityChange = useMemoizedFn(() => {
8
- if (!document.hidden) {
9
- debounceFn.run();
10
- }
11
- });
12
- useEffect(() => {
13
- window.addEventListener('focus', debounceFn.run);
14
- document.addEventListener('visibilitychange', handleVisibilityChange);
15
- return () => {
16
- window.removeEventListener('focus', debounceFn.run);
17
- document.removeEventListener('visibilitychange', handleVisibilityChange);
18
- };
19
- // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, []);
21
- return null;
22
- }
23
-
24
- WindowFocusAware.propTypes = {
25
- callback: PropTypes.func.isRequired,
26
- };
27
-
28
- export default WindowFocusAware;
@@ -1,2 +0,0 @@
1
- // eslint-disable-next-line no-restricted-exports
2
- export { default } from '@arcblock/ux/lib/SessionManager';
@@ -1,25 +0,0 @@
1
- import Cookie from 'js-cookie';
2
- import { getCookieOptions } from '@arcblock/ux/lib/Util';
3
- import { debugTmp } from '../../utils';
4
-
5
- export default class CookieStorageEngine {
6
- constructor(storageKey, options) {
7
- this.storageKey = storageKey;
8
- this.options = options || {};
9
- }
10
-
11
- setToken(token) {
12
- return Cookie.set(this.storageKey, token, {
13
- ...getCookieOptions(this.options),
14
- });
15
- }
16
-
17
- getToken() {
18
- return Cookie.get(this.storageKey);
19
- }
20
-
21
- removeToken() {
22
- debugTmp('[CookieStorageEngine] removeToken');
23
- return Cookie.remove(this.storageKey, getCookieOptions(this.options));
24
- }
25
- }
@@ -1,57 +0,0 @@
1
- import jwtDecode from 'jwt-decode';
2
- import { debugTmp } from '../../utils';
3
-
4
- export default class LocalStorageEngine {
5
- constructor(storageKey) {
6
- this.storageKey = storageKey;
7
- }
8
-
9
- setToken(token) {
10
- if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
11
- return undefined;
12
- }
13
-
14
- return localStorage.setItem(this.storageKey, token);
15
- }
16
-
17
- getToken() {
18
- if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
19
- return undefined;
20
- }
21
-
22
- const data = localStorage.getItem(this.storageKey);
23
- let value;
24
- let exp;
25
- try {
26
- ({ value, exp } = JSON.parse(data));
27
- // exp undefined 代表该结构不是有效的,所以应该直接返回 data
28
- if (exp === undefined || value === undefined) {
29
- // 从 value 中读取 exp
30
- return data;
31
- }
32
- } catch {
33
- value = data;
34
- }
35
-
36
- try {
37
- const decodeValue = jwtDecode(value);
38
- exp = decodeValue.exp;
39
- } catch {
40
- return undefined;
41
- }
42
-
43
- if (new Date().getTime() > exp * 1000) {
44
- return undefined;
45
- }
46
- return value;
47
- }
48
-
49
- removeToken() {
50
- debugTmp('[LocalStorageEngine] removeToken');
51
- if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
52
- return undefined;
53
- }
54
-
55
- return localStorage.removeItem(this.storageKey);
56
- }
57
- }
@@ -1,25 +0,0 @@
1
- import CookieEngine from './engine/cookie';
2
- import LocalStorageEngine from './engine/local-storage';
3
-
4
- export default function createStorage(storageKey = 'did.auth.token', storageEngine = 'ls', storageOptions = {}) {
5
- if (!storageKey) {
6
- throw new Error('storageKey must be specified to create a storage');
7
- }
8
-
9
- let storage = null;
10
- if (storageEngine === 'ls') {
11
- storage = new LocalStorageEngine(storageKey);
12
- } else if (storageEngine === 'cookie') {
13
- storage = new CookieEngine(storageKey, storageOptions);
14
- } else {
15
- throw new Error('storageEngine must be ls or cookie');
16
- }
17
-
18
- return {
19
- getToken: storage.getToken.bind(storage),
20
- setToken: storage.setToken.bind(storage),
21
- removeToken: storage.removeToken.bind(storage),
22
- engine: storageEngine,
23
- key: storageKey,
24
- };
25
- }
package/src/User/index.js DELETED
@@ -1,4 +0,0 @@
1
- import useDid from './use-did';
2
- import WrapDid from './wrap-did';
3
-
4
- export { useDid, WrapDid };
@@ -1,80 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
-
3
- // following utils duplicate from: arcblock/blocklet-server/blocklet/meta/src/did
4
- export function getPermanentDid(user) {
5
- return user?.did;
6
- }
7
-
8
- export function getConnectedAccounts(user) {
9
- return user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
10
- }
11
-
12
- export function getSourceProvider(user) {
13
- return user?.sourceProvider || user?.extraConfigs?.sourceProvider || 'wallet';
14
- }
15
-
16
- export function getSourceProviders(user) {
17
- const connectedAccounts = getConnectedAccounts(user);
18
- return connectedAccounts.map((item) => item.provider);
19
- }
20
-
21
- export function getConnectedDids(user) {
22
- const connectedAccounts = getConnectedAccounts(user);
23
- const didList = connectedAccounts.map((item) => item.did);
24
- return didList;
25
- }
26
-
27
- export function getWallet(user) {
28
- const connectedAccounts = getConnectedAccounts(user);
29
- const walletAccount = connectedAccounts.find((item) => item.provider === 'wallet');
30
- return walletAccount;
31
- }
32
- /**
33
- * @description
34
- * @export
35
- * @param {*} user
36
- * @return {string}
37
- */
38
- export function getWalletDid(user) {
39
- const walletAccount = getWallet(user);
40
- return walletAccount?.did;
41
- }
42
-
43
- function useDid({ session }) {
44
- const [state, setState] = useState({
45
- did: '',
46
- wallet: '',
47
- walletDid: '',
48
- permanentDid: '',
49
- connectedDids: [],
50
- connectedAccounts: [],
51
- sourceProvider: '',
52
- sourceProviders: [],
53
- });
54
- useEffect(() => {
55
- if (session?.user) {
56
- const permanentDid = getPermanentDid(session.user);
57
- const walletDid = getWalletDid(session.user);
58
- const connectedAccounts = getConnectedAccounts(session.user);
59
- const connectedDids = getConnectedDids(session.user);
60
- const wallet = getWallet(session.user);
61
- const sourceProvider = getSourceProvider(session.user);
62
- const sourceProviders = getSourceProviders(session.user);
63
-
64
- setState({
65
- did: permanentDid,
66
- wallet,
67
- walletDid,
68
- permanentDid,
69
- connectedDids,
70
- connectedAccounts,
71
- sourceProvider,
72
- sourceProviders,
73
- });
74
- }
75
- }, [session?.user]);
76
-
77
- return state;
78
- }
79
-
80
- export default useDid;
@@ -1,18 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import useDid from './use-did';
3
-
4
- function WrapDid({ session, children }) {
5
- const state = useDid({ session });
6
-
7
- if (children instanceof Function) {
8
- return children(state);
9
- }
10
- return null;
11
- }
12
-
13
- WrapDid.propTypes = {
14
- session: PropTypes.object.isRequired,
15
- children: PropTypes.func.isRequired,
16
- };
17
-
18
- export default WrapDid;
@@ -1,3 +0,0 @@
1
- export * from '@arcblock/ux/lib/WebWalletSWKeeper';
2
- // eslint-disable-next-line no-restricted-exports
3
- export { default } from '@arcblock/ux/lib/WebWalletSWKeeper';