@arcblock/did-connect-react 3.1.0
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/LICENSE +13 -0
- package/README.md +134 -0
- package/lib/Address/index.js +4 -0
- package/lib/Avatar/index.js +4 -0
- package/lib/Button/index.js +17 -0
- package/lib/Connect/assets/locale.js +143 -0
- package/lib/Connect/assets/login-bg.png +0 -0
- package/lib/Connect/assets/login-slogan.js +9 -0
- package/lib/Connect/components/action-button.js +26 -0
- package/lib/Connect/components/app-tips.js +132 -0
- package/lib/Connect/components/auto-height.js +31 -0
- package/lib/Connect/components/back-button.js +24 -0
- package/lib/Connect/components/connect-status.js +263 -0
- package/lib/Connect/components/did-connect-title.js +126 -0
- package/lib/Connect/components/download-tips.js +52 -0
- package/lib/Connect/components/loading.js +26 -0
- package/lib/Connect/components/login-item/connect-choose-list.js +249 -0
- package/lib/Connect/components/login-item/login-method-item.js +129 -0
- package/lib/Connect/components/login-item/mobile-login-item.js +114 -0
- package/lib/Connect/components/login-item/passkey-login-item.js +44 -0
- package/lib/Connect/components/login-item/web-login-item.js +97 -0
- package/lib/Connect/components/mask-overlay.js +34 -0
- package/lib/Connect/components/refresh-overlay.js +57 -0
- package/lib/Connect/components/switch-app.js +70 -0
- package/lib/Connect/contexts/state.js +142 -0
- package/lib/Connect/fullpage.js +5 -0
- package/lib/Connect/hooks/auth-url.js +23 -0
- package/lib/Connect/hooks/method-list.js +46 -0
- package/lib/Connect/hooks/page-show.js +17 -0
- package/lib/Connect/hooks/security.js +27 -0
- package/lib/Connect/hooks/token.js +305 -0
- package/lib/Connect/hooks/use-apps.js +19 -0
- package/lib/Connect/hooks/use-quick-connect.js +97 -0
- package/lib/Connect/index.js +498 -0
- package/lib/Connect/landing-page.js +5 -0
- package/lib/Connect/plugins/email/index.js +62 -0
- package/lib/Connect/plugins/email/list-item.js +28 -0
- package/lib/Connect/plugins/email/placeholder.js +283 -0
- package/lib/Connect/plugins/index.js +4 -0
- package/lib/Connect/use-connect.js +164 -0
- package/lib/Connect/with-blocklet.js +15 -0
- package/lib/Connect/with-bridge-call.js +108 -0
- package/lib/Federated/context.js +61 -0
- package/lib/Federated/index.js +7 -0
- package/lib/Logo/index.js +4 -0
- package/lib/OAuth/context.js +234 -0
- package/lib/OAuth/guest.svg.js +5 -0
- package/lib/OAuth/index.js +7 -0
- package/lib/OAuth/passport-switcher.js +114 -0
- package/lib/Passkey/actions.js +165 -0
- package/lib/Passkey/constants.js +4 -0
- package/lib/Passkey/context.js +266 -0
- package/lib/Passkey/dialog.js +277 -0
- package/lib/Passkey/icon.js +13 -0
- package/lib/Passkey/index.js +9 -0
- package/lib/Service/index.js +62 -0
- package/lib/Session/assets/did-spaces-guide-cover.svg.js +135 -0
- package/lib/Session/assets/did-spaces-guide-icon.svg.js +9 -0
- package/lib/Session/context.js +5 -0
- package/lib/Session/did-spaces-guide.js +136 -0
- package/lib/Session/hooks/use-federated.js +64 -0
- package/lib/Session/hooks/use-mobile.js +8 -0
- package/lib/Session/hooks/use-protected-routes.js +11 -0
- package/lib/Session/hooks/use-session-token.js +169 -0
- package/lib/Session/hooks/use-verify.js +45 -0
- package/lib/Session/index.js +896 -0
- package/lib/Session/libs/constants.js +15 -0
- package/lib/Session/libs/did-spaces.js +10 -0
- package/lib/Session/libs/federated.js +42 -0
- package/lib/Session/libs/index.js +15 -0
- package/lib/Session/libs/locales.js +161 -0
- package/lib/Session/libs/login-mobile.js +55 -0
- package/lib/Session/window-focus-aware.js +17 -0
- package/lib/SessionManager/index.js +4 -0
- package/lib/Storage/engine/cookie.js +21 -0
- package/lib/Storage/engine/local-storage.js +36 -0
- package/lib/Storage/index.js +23 -0
- package/lib/User/index.js +6 -0
- package/lib/User/use-did.js +59 -0
- package/lib/User/wrap-did.js +13 -0
- package/lib/WebWalletSWKeeper/index.js +5 -0
- package/lib/constant.js +22 -0
- package/lib/error.js +8 -0
- package/lib/hooks/use-locale.js +7 -0
- package/lib/index.js +33 -0
- package/lib/locales/en.js +17 -0
- package/lib/locales/index.js +10 -0
- package/lib/locales/zh.js +17 -0
- package/lib/package.json.js +7 -0
- package/lib/types.d.ts +355 -0
- package/lib/utils.js +214 -0
- package/package.json +84 -0
- package/src/Address/index.jsx +2 -0
- package/src/Avatar/index.jsx +2 -0
- package/src/Button/Button.stories.jsx +7 -0
- package/src/Button/index.jsx +21 -0
- package/src/Connect/Connect.stories.jsx +34 -0
- package/src/Connect/assets/locale.js +145 -0
- package/src/Connect/assets/login-bg.png +0 -0
- package/src/Connect/assets/login-slogan.js +7 -0
- package/src/Connect/components/action-button.jsx +22 -0
- package/src/Connect/components/app-tips.jsx +156 -0
- package/src/Connect/components/auto-height.jsx +38 -0
- package/src/Connect/components/back-button.jsx +23 -0
- package/src/Connect/components/connect-status.jsx +259 -0
- package/src/Connect/components/did-connect-title.jsx +106 -0
- package/src/Connect/components/download-tips.jsx +55 -0
- package/src/Connect/components/loading.jsx +25 -0
- package/src/Connect/components/login-item/connect-choose-list.jsx +304 -0
- package/src/Connect/components/login-item/login-method-item.jsx +118 -0
- package/src/Connect/components/login-item/mobile-login-item.jsx +179 -0
- package/src/Connect/components/login-item/passkey-login-item.jsx +52 -0
- package/src/Connect/components/login-item/web-login-item.jsx +149 -0
- package/src/Connect/components/mask-overlay.jsx +32 -0
- package/src/Connect/components/refresh-overlay.jsx +52 -0
- package/src/Connect/components/switch-app.jsx +69 -0
- package/src/Connect/contexts/state.jsx +219 -0
- package/src/Connect/fullpage.jsx +3 -0
- package/src/Connect/hooks/auth-url.js +31 -0
- package/src/Connect/hooks/method-list.js +121 -0
- package/src/Connect/hooks/page-show.js +24 -0
- package/src/Connect/hooks/security.js +40 -0
- package/src/Connect/hooks/token.js +639 -0
- package/src/Connect/hooks/use-apps.js +69 -0
- package/src/Connect/hooks/use-quick-connect.js +130 -0
- package/src/Connect/index.jsx +600 -0
- package/src/Connect/landing-page.jsx +3 -0
- package/src/Connect/plugins/email/index.jsx +82 -0
- package/src/Connect/plugins/email/list-item.jsx +31 -0
- package/src/Connect/plugins/email/placeholder.jsx +365 -0
- package/src/Connect/plugins/index.js +2 -0
- package/src/Connect/use-connect.jsx +321 -0
- package/src/Connect/with-blocklet.jsx +26 -0
- package/src/Connect/with-bridge-call.jsx +138 -0
- package/src/Federated/context.jsx +93 -0
- package/src/Federated/index.jsx +1 -0
- package/src/Logo/index.jsx +2 -0
- package/src/OAuth/context.jsx +346 -0
- package/src/OAuth/guest.svg +20 -0
- package/src/OAuth/index.jsx +1 -0
- package/src/OAuth/passport-switcher.jsx +133 -0
- package/src/Passkey/actions.jsx +212 -0
- package/src/Passkey/constants.js +2 -0
- package/src/Passkey/context.jsx +381 -0
- package/src/Passkey/dialog.jsx +391 -0
- package/src/Passkey/icon.jsx +10 -0
- package/src/Passkey/index.jsx +2 -0
- package/src/Service/index.jsx +96 -0
- package/src/Session/assets/did-spaces-guide-cover.svg +128 -0
- package/src/Session/assets/did-spaces-guide-icon.svg +7 -0
- package/src/Session/context.jsx +7 -0
- package/src/Session/did-spaces-guide.jsx +173 -0
- package/src/Session/hooks/use-federated.js +88 -0
- package/src/Session/hooks/use-mobile.jsx +6 -0
- package/src/Session/hooks/use-protected-routes.js +16 -0
- package/src/Session/hooks/use-session-token.js +365 -0
- package/src/Session/hooks/use-verify.jsx +76 -0
- package/src/Session/index.jsx +1687 -0
- package/src/Session/libs/constants.js +14 -0
- package/src/Session/libs/did-spaces.js +38 -0
- package/src/Session/libs/federated.js +79 -0
- package/src/Session/libs/index.js +5 -0
- package/src/Session/libs/locales.js +160 -0
- package/src/Session/libs/login-mobile.js +80 -0
- package/src/Session/window-focus-aware.jsx +28 -0
- package/src/SessionManager/index.jsx +2 -0
- package/src/Storage/engine/cookie.js +23 -0
- package/src/Storage/engine/local-storage.js +55 -0
- package/src/Storage/index.js +25 -0
- package/src/User/index.js +4 -0
- package/src/User/use-did.js +80 -0
- package/src/User/wrap-did.jsx +18 -0
- package/src/WebWalletSWKeeper/index.jsx +3 -0
- package/src/constant.js +26 -0
- package/src/error.js +6 -0
- package/src/hooks/use-locale.jsx +6 -0
- package/src/index.js +43 -0
- package/src/locales/en.jsx +15 -0
- package/src/locales/index.jsx +13 -0
- package/src/locales/zh.jsx +15 -0
- package/src/types.d.ts +355 -0
- package/src/utils.js +395 -0
- package/vite.config.mjs +29 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Address from './Address';
|
|
2
|
+
import Avatar from './Avatar';
|
|
3
|
+
import Button from './Button';
|
|
4
|
+
import DidConnect from './Connect';
|
|
5
|
+
import Logo from './Logo';
|
|
6
|
+
import { OAuthContext, OAuthConsumer, OAuthProvider, useOAuth } from './OAuth';
|
|
7
|
+
import { PasskeyContext, PasskeyConsumer, PasskeyProvider, usePasskey, PasskeyActions } from './Passkey';
|
|
8
|
+
import Session from './Session';
|
|
9
|
+
import SessionManager from './SessionManager';
|
|
10
|
+
import { useDid, WrapDid } from './User';
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
// Core Components
|
|
14
|
+
Address,
|
|
15
|
+
Avatar,
|
|
16
|
+
Button,
|
|
17
|
+
|
|
18
|
+
// DID Connect
|
|
19
|
+
DidConnect,
|
|
20
|
+
DidConnect as Connect,
|
|
21
|
+
Logo,
|
|
22
|
+
|
|
23
|
+
// Session Management
|
|
24
|
+
Session,
|
|
25
|
+
SessionManager,
|
|
26
|
+
|
|
27
|
+
// OAuth Features
|
|
28
|
+
OAuthContext,
|
|
29
|
+
OAuthConsumer,
|
|
30
|
+
OAuthProvider,
|
|
31
|
+
useOAuth,
|
|
32
|
+
|
|
33
|
+
// Passkey Features
|
|
34
|
+
PasskeyContext,
|
|
35
|
+
PasskeyConsumer,
|
|
36
|
+
PasskeyProvider,
|
|
37
|
+
usePasskey,
|
|
38
|
+
PasskeyActions,
|
|
39
|
+
|
|
40
|
+
// User Management
|
|
41
|
+
useDid,
|
|
42
|
+
WrapDid,
|
|
43
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import flat from 'flat';
|
|
2
|
+
|
|
3
|
+
export default flat({
|
|
4
|
+
didSpacesGuide: {
|
|
5
|
+
title: 'Connect to DID Spaces',
|
|
6
|
+
description: 'Your secure, private, and reliable decentralized digital storage space.',
|
|
7
|
+
feature: {
|
|
8
|
+
dataSecurity: 'Data Security',
|
|
9
|
+
dataSharing: 'Data Sharing',
|
|
10
|
+
dataSync: 'Data Sync',
|
|
11
|
+
dataIntegration: 'Data Integration',
|
|
12
|
+
},
|
|
13
|
+
connectNow: 'Connect Now',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
import en from './en';
|
|
3
|
+
import zh from './zh';
|
|
4
|
+
|
|
5
|
+
const locales = { en, zh };
|
|
6
|
+
|
|
7
|
+
const replace = (template, data) =>
|
|
8
|
+
template.replace(/{(\w*)}/g, (_, key) => (Object.prototype.hasOwnProperty.call(data, key) ? data[key] : ''));
|
|
9
|
+
|
|
10
|
+
export function t(key, locale = 'en', params = {}) {
|
|
11
|
+
const _locale = locale in locales ? locale : 'en';
|
|
12
|
+
return replace(locales[_locale][key], params) || key;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import flat from 'flat';
|
|
2
|
+
|
|
3
|
+
export default flat({
|
|
4
|
+
didSpacesGuide: {
|
|
5
|
+
title: '连接到 DID Spaces',
|
|
6
|
+
description: '您的安全、私密、可靠的分散式数字存储空间。',
|
|
7
|
+
feature: {
|
|
8
|
+
dataSecurity: '数据安全',
|
|
9
|
+
dataSharing: '数据共享',
|
|
10
|
+
dataSync: '数据同步',
|
|
11
|
+
dataIntegration: '数据集成',
|
|
12
|
+
},
|
|
13
|
+
connectNow: '立即连接',
|
|
14
|
+
},
|
|
15
|
+
});
|
package/src/types.d.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
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
|
+
};
|