@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.
- package/dist/standalone/did-connect-react.css +1 -0
- package/dist/standalone/index.js +133700 -0
- package/lib/package.json.js +1 -1
- package/package.json +11 -6
- package/.aigne/doc-smith/config.yaml +0 -85
- package/.aigne/doc-smith/history.yaml +0 -6
- package/.aigne/doc-smith/output/structure-plan.json +0 -204
- package/.aigne/doc-smith/translation-cache.yaml +0 -11
- package/.aigne/doc-smith/upload-cache.yaml +0 -213
- package/docs/_sidebar.md +0 -18
- package/docs/advanced-authentication-methods.ja.md +0 -261
- package/docs/advanced-authentication-methods.md +0 -261
- package/docs/advanced-authentication-methods.zh-TW.md +0 -261
- package/docs/advanced-authentication-methods.zh.md +0 -261
- package/docs/advanced-utilities.ja.md +0 -132
- package/docs/advanced-utilities.md +0 -132
- package/docs/advanced-utilities.zh-TW.md +0 -132
- package/docs/advanced-utilities.zh.md +0 -132
- package/docs/advanced.ja.md +0 -95
- package/docs/advanced.md +0 -95
- package/docs/advanced.zh-TW.md +0 -95
- package/docs/advanced.zh.md +0 -95
- package/docs/api-reference.ja.md +0 -178
- package/docs/api-reference.md +0 -178
- package/docs/api-reference.zh-TW.md +0 -178
- package/docs/api-reference.zh.md +0 -178
- package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/overview-01.ja.jpg +0 -0
- package/docs/assets/diagram/overview-01.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
- package/docs/core-components-did-connect.ja.md +0 -166
- package/docs/core-components-did-connect.md +0 -166
- package/docs/core-components-did-connect.zh-TW.md +0 -166
- package/docs/core-components-did-connect.zh.md +0 -166
- package/docs/core-components-session-provider.ja.md +0 -197
- package/docs/core-components-session-provider.md +0 -197
- package/docs/core-components-session-provider.zh-TW.md +0 -197
- package/docs/core-components-session-provider.zh.md +0 -197
- package/docs/core-components.ja.md +0 -16
- package/docs/core-components.md +0 -16
- package/docs/core-components.zh-TW.md +0 -16
- package/docs/core-components.zh.md +0 -16
- package/docs/getting-started.ja.md +0 -138
- package/docs/getting-started.md +0 -138
- package/docs/getting-started.zh-TW.md +0 -138
- package/docs/getting-started.zh.md +0 -138
- package/docs/hooks-use-connect.ja.md +0 -178
- package/docs/hooks-use-connect.md +0 -178
- package/docs/hooks-use-connect.zh-TW.md +0 -178
- package/docs/hooks-use-connect.zh.md +0 -178
- package/docs/hooks-use-did.ja.md +0 -107
- package/docs/hooks-use-did.md +0 -107
- package/docs/hooks-use-did.zh-TW.md +0 -107
- package/docs/hooks-use-did.zh.md +0 -107
- package/docs/hooks-use-oauth-passkey.ja.md +0 -188
- package/docs/hooks-use-oauth-passkey.md +0 -188
- package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
- package/docs/hooks-use-oauth-passkey.zh.md +0 -188
- package/docs/hooks.ja.md +0 -23
- package/docs/hooks.md +0 -23
- package/docs/hooks.zh-TW.md +0 -23
- package/docs/hooks.zh.md +0 -23
- package/docs/overview.ja.md +0 -119
- package/docs/overview.md +0 -119
- package/docs/overview.zh-TW.md +0 -119
- package/docs/overview.zh.md +0 -119
- package/docs/ui-components-address.ja.md +0 -121
- package/docs/ui-components-address.md +0 -121
- package/docs/ui-components-address.zh-TW.md +0 -121
- package/docs/ui-components-address.zh.md +0 -121
- package/docs/ui-components-avatar.ja.md +0 -65
- package/docs/ui-components-avatar.md +0 -65
- package/docs/ui-components-avatar.zh-TW.md +0 -65
- package/docs/ui-components-avatar.zh.md +0 -65
- package/docs/ui-components-button.ja.md +0 -99
- package/docs/ui-components-button.md +0 -99
- package/docs/ui-components-button.zh-TW.md +0 -99
- package/docs/ui-components-button.zh.md +0 -99
- package/docs/ui-components-logo.ja.md +0 -52
- package/docs/ui-components-logo.md +0 -52
- package/docs/ui-components-logo.zh-TW.md +0 -52
- package/docs/ui-components-logo.zh.md +0 -52
- package/docs/ui-components.ja.md +0 -57
- package/docs/ui-components.md +0 -57
- package/docs/ui-components.zh-TW.md +0 -57
- package/docs/ui-components.zh.md +0 -57
- package/glossary.md +0 -1
- package/src/Address/index.jsx +0 -2
- package/src/Avatar/index.jsx +0 -2
- package/src/Button/Button.stories.jsx +0 -7
- package/src/Button/index.jsx +0 -21
- package/src/Connect/Connect.stories.jsx +0 -34
- package/src/Connect/assets/locale.js +0 -149
- package/src/Connect/assets/login-bg.png +0 -0
- package/src/Connect/assets/login-slogan.js +0 -7
- package/src/Connect/components/action-button.jsx +0 -22
- package/src/Connect/components/app-tips.jsx +0 -156
- package/src/Connect/components/auto-height.jsx +0 -38
- package/src/Connect/components/back-button.jsx +0 -24
- package/src/Connect/components/connect-status.jsx +0 -259
- package/src/Connect/components/did-connect-title.jsx +0 -107
- package/src/Connect/components/download-tips.jsx +0 -55
- package/src/Connect/components/loading.jsx +0 -25
- package/src/Connect/components/login-item/connect-choose-list.jsx +0 -328
- package/src/Connect/components/login-item/connect-provider-list.jsx +0 -473
- package/src/Connect/components/login-item/login-method-item.jsx +0 -139
- package/src/Connect/components/login-item/mobile-login-item.jsx +0 -184
- package/src/Connect/components/login-item/passkey-login-item.jsx +0 -56
- package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
- package/src/Connect/components/login-item/web-login-item.jsx +0 -159
- package/src/Connect/components/mask-overlay.jsx +0 -32
- package/src/Connect/components/refresh-overlay.jsx +0 -52
- package/src/Connect/components/switch-app.jsx +0 -69
- package/src/Connect/connect.jsx +0 -635
- package/src/Connect/contexts/state.jsx +0 -235
- package/src/Connect/fallback-connect.jsx +0 -47
- package/src/Connect/fullpage.jsx +0 -3
- package/src/Connect/hooks/auth-url.js +0 -31
- package/src/Connect/hooks/method-list.js +0 -121
- package/src/Connect/hooks/page-show.js +0 -24
- package/src/Connect/hooks/provider-list.js +0 -168
- package/src/Connect/hooks/security.js +0 -40
- package/src/Connect/hooks/token.js +0 -627
- package/src/Connect/hooks/use-apps.js +0 -69
- package/src/Connect/hooks/use-quick-connect.js +0 -119
- package/src/Connect/index.jsx +0 -21
- package/src/Connect/landing-page.jsx +0 -3
- package/src/Connect/plugins/email/index.jsx +0 -85
- package/src/Connect/plugins/email/list-item.jsx +0 -35
- package/src/Connect/plugins/email/placeholder.jsx +0 -372
- package/src/Connect/plugins/index.js +0 -2
- package/src/Connect/use-connect.jsx +0 -321
- package/src/Connect/with-blocklet.jsx +0 -26
- package/src/Connect/with-bridge-call.jsx +0 -138
- package/src/Federated/context.jsx +0 -93
- package/src/Federated/index.jsx +0 -1
- package/src/Logo/index.jsx +0 -2
- package/src/OAuth/bind-conflict-alert.jsx +0 -37
- package/src/OAuth/context.jsx +0 -407
- package/src/OAuth/guest.svg +0 -20
- package/src/OAuth/index.jsx +0 -1
- package/src/OAuth/passport-switcher.jsx +0 -2
- package/src/Passkey/actions.jsx +0 -217
- package/src/Passkey/constants.js +0 -2
- package/src/Passkey/context.jsx +0 -395
- package/src/Passkey/dialog.jsx +0 -401
- package/src/Passkey/icon.jsx +0 -10
- package/src/Passkey/index.jsx +0 -2
- package/src/Service/index.jsx +0 -96
- package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
- package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
- package/src/Session/context.jsx +0 -7
- package/src/Session/did-spaces-guide.jsx +0 -173
- package/src/Session/handler.jsx +0 -98
- package/src/Session/hooks/use-federated.js +0 -91
- package/src/Session/hooks/use-mobile.jsx +0 -6
- package/src/Session/hooks/use-protected-routes.js +0 -16
- package/src/Session/hooks/use-session-token.js +0 -400
- package/src/Session/hooks/use-verify.jsx +0 -76
- package/src/Session/index.jsx +0 -1789
- package/src/Session/libs/constants.js +0 -17
- package/src/Session/libs/did-spaces.js +0 -38
- package/src/Session/libs/federated.js +0 -82
- package/src/Session/libs/index.js +0 -5
- package/src/Session/libs/locales.js +0 -160
- package/src/Session/libs/login-mobile.js +0 -80
- package/src/Session/window-focus-aware.jsx +0 -28
- package/src/SessionManager/index.jsx +0 -2
- package/src/Storage/engine/cookie.js +0 -25
- package/src/Storage/engine/local-storage.js +0 -57
- package/src/Storage/index.js +0 -25
- package/src/User/index.js +0 -4
- package/src/User/use-did.js +0 -80
- package/src/User/wrap-did.jsx +0 -18
- package/src/WebWalletSWKeeper/index.jsx +0 -3
- package/src/components/PassportSwitcher.jsx +0 -160
- package/src/constant.js +0 -27
- package/src/error.js +0 -6
- package/src/hooks/use-locale.jsx +0 -6
- package/src/index.js +0 -32
- package/src/locales/en.jsx +0 -15
- package/src/locales/index.jsx +0 -13
- package/src/locales/zh.jsx +0 -15
- package/src/types.d.ts +0 -355
- package/src/utils.js +0 -413
- package/vite.config.mjs +0 -29
package/docs/overview.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# Overview
|
|
2
|
-
|
|
3
|
-
The `@arcblock/did-connect-react` library provides a comprehensive set of React components and hooks designed to seamlessly integrate decentralized identity (DID) capabilities into your web applications. It simplifies the process of user authentication and session management using ArcBlock's DID Wallet, offering a secure and user-friendly alternative to traditional login systems.
|
|
4
|
-
|
|
5
|
-
This library is built to be flexible and easy to use, whether you need a complete out-of-the-box solution or granular control over the authentication flow.
|
|
6
|
-
|
|
7
|
-
### Key Features
|
|
8
|
-
|
|
9
|
-
<x-cards data-columns="2">
|
|
10
|
-
<x-card data-title="Complete Connection UI" data-icon="lucide:qr-code-icon">
|
|
11
|
-
Includes the `DidConnect` component, a pre-built, customizable modal for handling the entire QR code scanning and connection process.
|
|
12
|
-
</x-card>
|
|
13
|
-
<x-card data-title="Seamless Session Management" data-icon="lucide:key-round">
|
|
14
|
-
Leverage the `SessionProvider` and `useSession` hook to effortlessly manage user login states, sessions, and profile data throughout your application.
|
|
15
|
-
</x-card>
|
|
16
|
-
<x-card data-title="Flexible Programmatic Control" data-icon="lucide:webhook">
|
|
17
|
-
Use hooks like `useConnect` to programmatically open, close, and manage the connection modal, giving you full control over the user experience.
|
|
18
|
-
</x-card>
|
|
19
|
-
<x-card data-title="Rich UI Toolkit" data-icon="lucide:gem">
|
|
20
|
-
A collection of supplementary UI components like `Avatar`, `Address`, and `Button` to display user identity information consistently.
|
|
21
|
-
</x-card>
|
|
22
|
-
</x-cards>
|
|
23
|
-
|
|
24
|
-
### Core Architecture
|
|
25
|
-
|
|
26
|
-
The library revolves around a central `SessionProvider` that manages the user's session state. UI components like `Button` can trigger the `DidConnect` modal, which handles the secure, QR-code-based interaction with the user's DID Wallet. Once the connection is complete, the session is updated, and your application's UI reacts accordingly.
|
|
27
|
-
|
|
28
|
-
It's important to note that `@arcblock/did-connect-react` is a client-side library and requires a corresponding backend service to handle the authentication logic. This service should be built using the [`@arcblock/did-connect-js`](https://www.arcblock.io/docs/did-connect-sdk) library for Node.js.
|
|
29
|
-
|
|
30
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
31
|
-

|
|
32
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
33
|
-
|
|
34
|
-
### Installation
|
|
35
|
-
|
|
36
|
-
To get started, add the library to your project using `yarn` or `npm`.
|
|
37
|
-
|
|
38
|
-
```shell Installation icon=lucide:download
|
|
39
|
-
# With yarn
|
|
40
|
-
yarn add @arcblock/did-connect-react
|
|
41
|
-
|
|
42
|
-
# With npm
|
|
43
|
-
npm install @arcblock/did-connect-react
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### How It Works: A Quick Look
|
|
47
|
-
|
|
48
|
-
Here is a minimal example of how to set up a login flow. The application is wrapped in a `SessionProvider`, and a `Button` is used to toggle the `DidConnect` modal.
|
|
49
|
-
|
|
50
|
-
```jsx App.js icon=logos:react
|
|
51
|
-
import React from 'react';
|
|
52
|
-
import axios from 'axios';
|
|
53
|
-
import { SessionProvider, SessionConsumer } from '@arcblock/did-connect-react/lib/Session';
|
|
54
|
-
import DidConnect from '@arcblock/did-connect-react/lib/Connect';
|
|
55
|
-
import Button from '@arcblock/did-connect-react/lib/Button';
|
|
56
|
-
|
|
57
|
-
const webWalletUrl = 'https://web.abtwallet.io/';
|
|
58
|
-
|
|
59
|
-
function App() {
|
|
60
|
-
const [isConnectOpen, setConnectOpen] = React.useState(false);
|
|
61
|
-
|
|
62
|
-
const handleClose = () => setConnectOpen(false);
|
|
63
|
-
const handleSuccess = () => {
|
|
64
|
-
// Redirect or update UI after successful login
|
|
65
|
-
window.location.reload();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<SessionProvider serviceHost="/">
|
|
70
|
-
<div className="main-content">
|
|
71
|
-
<SessionConsumer>
|
|
72
|
-
{({ session }) => {
|
|
73
|
-
if (session.loading) {
|
|
74
|
-
return <div>Loading session...</div>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return session.user ? (
|
|
78
|
-
<div>
|
|
79
|
-
<h2>Welcome, {session.user.did}!</h2>
|
|
80
|
-
<button onClick={() => session.logout()}>Logout</button>
|
|
81
|
-
</div>
|
|
82
|
-
) : (
|
|
83
|
-
<Button onClick={() => setConnectOpen(true)}>Connect Wallet</Button>
|
|
84
|
-
);
|
|
85
|
-
}}
|
|
86
|
-
</SessionConsumer>
|
|
87
|
-
</div>
|
|
88
|
-
|
|
89
|
-
<DidConnect
|
|
90
|
-
popup
|
|
91
|
-
open={isConnectOpen}
|
|
92
|
-
action="login"
|
|
93
|
-
checkFn={axios.get}
|
|
94
|
-
onClose={handleClose}
|
|
95
|
-
onSuccess={handleSuccess}
|
|
96
|
-
messages={{
|
|
97
|
-
title: 'Login to My App',
|
|
98
|
-
scan: 'Scan QR code with your DID Wallet',
|
|
99
|
-
confirm: 'Confirm login on your wallet',
|
|
100
|
-
success: 'You have successfully signed in!',
|
|
101
|
-
}}
|
|
102
|
-
webWalletUrl={webWalletUrl}
|
|
103
|
-
/>
|
|
104
|
-
</SessionProvider>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default App;
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
This example demonstrates how to manage user sessions and trigger the login process with just a few components.
|
|
112
|
-
|
|
113
|
-
### Next Steps
|
|
114
|
-
|
|
115
|
-
Now that you have a basic understanding of the library, you're ready to dive deeper.
|
|
116
|
-
|
|
117
|
-
<x-card data-title="Getting Started" data-href="/getting-started" data-icon="lucide:rocket" data-cta="Start Building">
|
|
118
|
-
Follow our step-by-step guide to integrate DID Connect into your own application from scratch.
|
|
119
|
-
</x-card>
|
package/docs/overview.zh-TW.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# 總覽
|
|
2
|
-
|
|
3
|
-
`@arcblock/did-connect-react` 程式庫提供了一套全面的 React 元件和掛鉤 (hooks),旨在將去中心化身分 (DID) 功能無縫整合到您的 Web 應用程式中。它使用 ArcBlock 的 DID Wallet 簡化了使用者驗證和會話管理的流程,為傳統登入系統提供了一個安全且使用者友善的替代方案。
|
|
4
|
-
|
|
5
|
-
無論您需要一個完整的開箱即用解決方案,還是對驗證流程進行精細控制,該程式庫的設計都兼具靈活性和易用性。
|
|
6
|
-
|
|
7
|
-
### 主要功能
|
|
8
|
-
|
|
9
|
-
<x-cards data-columns="2">
|
|
10
|
-
<x-card data-title="完整的連線 UI" data-icon="lucide:qr-code-icon">
|
|
11
|
-
包含 `DidConnect` 元件,這是一個預先建置、可自訂的對話方塊,用於處理整個 QR Code 掃描和連線過程。
|
|
12
|
-
</x-card>
|
|
13
|
-
<x-card data-title="無縫的會話管理" data-icon="lucide:key-round">
|
|
14
|
-
利用 `SessionProvider` 和 `useSession` 掛鉤,輕鬆管理整個應用程式中的使用者登入狀態、會話和個人資料。
|
|
15
|
-
</x-card>
|
|
16
|
-
<x-card data-title="靈活的程式化控制" data-icon="lucide:webhook">
|
|
17
|
-
使用像 `useConnect` 這樣的掛鉤,以程式化方式開啟、關閉和管理連線對話方塊,讓您完全掌控使用者體驗。
|
|
18
|
-
</x-card>
|
|
19
|
-
<x-card data-title="豐富的 UI 工具組" data-icon="lucide:gem">
|
|
20
|
-
一系列輔助 UI 元件,如 `Avatar`、`Address` 和 `Button`,用於一致地顯示使用者身分資訊。
|
|
21
|
-
</x-card>
|
|
22
|
-
</x-cards>
|
|
23
|
-
|
|
24
|
-
### 核心架構
|
|
25
|
-
|
|
26
|
-
該程式庫圍繞一個核心的 `SessionProvider` 運作,它負責管理使用者的會話狀態。像 `Button` 這樣的 UI 元件可以觸發 `DidConnect` 對話方塊,該對話方塊處理與使用者 DID Wallet 之間基於 QR Code 的安全互動。連線完成後,會話將被更新,您的應用程式 UI 也會做出相應的反應。
|
|
27
|
-
|
|
28
|
-
需要注意的是,`@arcblock/did-connect-react` 是一個用戶端程式庫,需要一個對應的後端服務來處理驗證邏輯。該服務應使用適用於 Node.js 的 [`@arcblock/did-connect-js`](https://www.arcblock.io/docs/did-connect-sdk) 程式庫來建構。
|
|
29
|
-
|
|
30
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
31
|
-

|
|
32
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
33
|
-
|
|
34
|
-
### 安裝
|
|
35
|
-
|
|
36
|
-
若要開始使用,請使用 `yarn` 或 `npm` 將該程式庫新增至您的專案中。
|
|
37
|
-
|
|
38
|
-
```shell 安裝 icon=lucide:download
|
|
39
|
-
# 使用 yarn
|
|
40
|
-
yarn add @arcblock/did-connect-react
|
|
41
|
-
|
|
42
|
-
# 使用 npm
|
|
43
|
-
npm install @arcblock/did-connect-react
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 運作方式:快速概覽
|
|
47
|
-
|
|
48
|
-
以下是一個如何設定登入流程的最小範例。應用程式被包裹在一個 `SessionProvider` 中,並使用一個 `Button` 來切換 `DidConnect` 對話方塊的顯示。
|
|
49
|
-
|
|
50
|
-
```jsx App.js icon=logos:react
|
|
51
|
-
import React from 'react';
|
|
52
|
-
import axios from 'axios';
|
|
53
|
-
import { SessionProvider, SessionConsumer } from '@arcblock/did-connect-react/lib/Session';
|
|
54
|
-
import DidConnect from '@arcblock/did-connect-react/lib/Connect';
|
|
55
|
-
import Button from '@arcblock/did-connect-react/lib/Button';
|
|
56
|
-
|
|
57
|
-
const webWalletUrl = 'https://web.abtwallet.io/';
|
|
58
|
-
|
|
59
|
-
function App() {
|
|
60
|
-
const [isConnectOpen, setConnectOpen] = React.useState(false);
|
|
61
|
-
|
|
62
|
-
const handleClose = () => setConnectOpen(false);
|
|
63
|
-
const handleSuccess = () => {
|
|
64
|
-
// 成功登入後重新導向或更新 UI
|
|
65
|
-
window.location.reload();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<SessionProvider serviceHost="/">
|
|
70
|
-
<div className="main-content">
|
|
71
|
-
<SessionConsumer>
|
|
72
|
-
{({ session }) => {
|
|
73
|
-
if (session.loading) {
|
|
74
|
-
return <div>Loading session...</div>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return session.user ? (
|
|
78
|
-
<div>
|
|
79
|
-
<h2>Welcome, {session.user.did}!</h2>
|
|
80
|
-
<button onClick={() => session.logout()}>Logout</button>
|
|
81
|
-
</div>
|
|
82
|
-
) : (
|
|
83
|
-
<Button onClick={() => setConnectOpen(true)}>Connect Wallet</Button>
|
|
84
|
-
);
|
|
85
|
-
}}
|
|
86
|
-
</SessionConsumer>
|
|
87
|
-
</div>
|
|
88
|
-
|
|
89
|
-
<DidConnect
|
|
90
|
-
popup
|
|
91
|
-
open={isConnectOpen}
|
|
92
|
-
action="login"
|
|
93
|
-
checkFn={axios.get}
|
|
94
|
-
onClose={handleClose}
|
|
95
|
-
onSuccess={handleSuccess}
|
|
96
|
-
messages={{
|
|
97
|
-
title: 'Login to My App',
|
|
98
|
-
scan: 'Scan QR code with your DID Wallet',
|
|
99
|
-
confirm: 'Confirm login on your wallet',
|
|
100
|
-
success: 'You have successfully signed in!',
|
|
101
|
-
}}
|
|
102
|
-
webWalletUrl={webWalletUrl}
|
|
103
|
-
/>
|
|
104
|
-
</SessionProvider>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default App;
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
此範例展示了如何僅用幾個元件來管理使用者會話並觸發登入過程。
|
|
112
|
-
|
|
113
|
-
### 後續步驟
|
|
114
|
-
|
|
115
|
-
現在您已對該程式庫有了基本了解,可以準備進行更深入的探索。
|
|
116
|
-
|
|
117
|
-
<x-card data-title="開始使用" data-href="/getting-started" data-icon="lucide:rocket" data-cta="開始建構">
|
|
118
|
-
跟隨我們的逐步指南,從頭開始將 DID Connect 整合到您自己的應用程式中。
|
|
119
|
-
</x-card>
|
package/docs/overview.zh.md
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
# 概述
|
|
2
|
-
|
|
3
|
-
`@arcblock/did-connect-react` 库提供了一套全面的 React 组件和钩子,旨在将去中心化身份 (DID) 功能无缝集成到您的 Web 应用程序中。它使用 ArcBlock 的 DID 钱包简化了用户身份验证和会话管理的过程,为传统的登录系统提供了一种安全且用户友好的替代方案。
|
|
4
|
-
|
|
5
|
-
该库的设计灵活且易于使用,无论您需要一个完整的开箱即用解决方案,还是对身份验证流程进行精细控制,它都能满足您的需求。
|
|
6
|
-
|
|
7
|
-
### 主要特性
|
|
8
|
-
|
|
9
|
-
<x-cards data-columns="2">
|
|
10
|
-
<x-card data-title="完整的连接用户界面" data-icon="lucide:qr-code-icon">
|
|
11
|
-
包含 `DidConnect` 组件,这是一个预制的、可定制的模态框,用于处理整个二维码扫描和连接过程。
|
|
12
|
-
</x-card>
|
|
13
|
-
<x-card data-title="无缝的会话管理" data-icon="lucide:key-round">
|
|
14
|
-
利用 `SessionProvider` 和 `useSession` 钩子,在您的整个应用程序中轻松管理用户登录状态、会话和个人资料数据。
|
|
15
|
-
</x-card>
|
|
16
|
-
<x-card data-title="灵活的编程控制" data-icon="lucide:webhook">
|
|
17
|
-
使用 `useConnect` 等钩子以编程方式打开、关闭和管理连接模态框,让您完全控制用户体验。
|
|
18
|
-
</x-card>
|
|
19
|
-
<x-card data-title="丰富的 UI 工具包" data-icon="lucide:gem">
|
|
20
|
-
一系列辅助 UI 组件,如 `Avatar`、`Address` 和 `Button`,用于一致地显示用户身份信息。
|
|
21
|
-
</x-card>
|
|
22
|
-
</x-cards>
|
|
23
|
-
|
|
24
|
-
### 核心架构
|
|
25
|
-
|
|
26
|
-
该库围绕一个核心的 `SessionProvider` 展开,它负责管理用户的会话状态。像 `Button` 这样的 UI 组件可以触发 `DidConnect` 模态框,该模态框处理与用户 DID 钱包之间基于二维码的安全交互。连接完成后,会话将被更新,您的应用程序 UI 会相应地做出反应。
|
|
27
|
-
|
|
28
|
-
需要注意的是,`@arcblock/did-connect-react` 是一个客户端库,需要相应的后端服务来处理身份验证逻辑。该服务应使用适用于 Node.js 的 [`@arcblock/did-connect-js`](https://www.arcblock.io/docs/did-connect-sdk) 库来构建。
|
|
29
|
-
|
|
30
|
-
<!-- DIAGRAM_IMAGE_START:architecture:16:9:1765962229 -->
|
|
31
|
-

|
|
32
|
-
<!-- DIAGRAM_IMAGE_END -->
|
|
33
|
-
|
|
34
|
-
### 安装
|
|
35
|
-
|
|
36
|
-
首先,使用 `yarn` 或 `npm` 将该库添加到您的项目中。
|
|
37
|
-
|
|
38
|
-
```shell 安装 icon=lucide:download
|
|
39
|
-
# 使用 yarn
|
|
40
|
-
yarn add @arcblock/did-connect-react
|
|
41
|
-
|
|
42
|
-
# 使用 npm
|
|
43
|
-
npm install @arcblock/did-connect-react
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 工作原理简介
|
|
47
|
-
|
|
48
|
-
以下是一个如何设置登录流程的最小示例。应用程序被包裹在 `SessionProvider` 中,并使用一个 `Button` 来切换 `DidConnect` 模态框的显示。
|
|
49
|
-
|
|
50
|
-
```jsx App.js icon=logos:react
|
|
51
|
-
import React from 'react';
|
|
52
|
-
import axios from 'axios';
|
|
53
|
-
import { SessionProvider, SessionConsumer } from '@arcblock/did-connect-react/lib/Session';
|
|
54
|
-
import DidConnect from '@arcblock/did-connect-react/lib/Connect';
|
|
55
|
-
import Button from '@arcblock/did-connect-react/lib/Button';
|
|
56
|
-
|
|
57
|
-
const webWalletUrl = 'https://web.abtwallet.io/';
|
|
58
|
-
|
|
59
|
-
function App() {
|
|
60
|
-
const [isConnectOpen, setConnectOpen] = React.useState(false);
|
|
61
|
-
|
|
62
|
-
const handleClose = () => setConnectOpen(false);
|
|
63
|
-
const handleSuccess = () => {
|
|
64
|
-
// 登录成功后重定向或更新 UI
|
|
65
|
-
window.location.reload();
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<SessionProvider serviceHost="/">
|
|
70
|
-
<div className="main-content">
|
|
71
|
-
<SessionConsumer>
|
|
72
|
-
{({ session }) => {
|
|
73
|
-
if (session.loading) {
|
|
74
|
-
return <div>正在加载会话...</div>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return session.user ? (
|
|
78
|
-
<div>
|
|
79
|
-
<h2>欢迎, {session.user.did}!</h2>
|
|
80
|
-
<button onClick={() => session.logout()}>登出</button>
|
|
81
|
-
</div>
|
|
82
|
-
) : (
|
|
83
|
-
<Button onClick={() => setConnectOpen(true)}>连接钱包</Button>
|
|
84
|
-
);
|
|
85
|
-
}}
|
|
86
|
-
</SessionConsumer>
|
|
87
|
-
</div>
|
|
88
|
-
|
|
89
|
-
<DidConnect
|
|
90
|
-
popup
|
|
91
|
-
open={isConnectOpen}
|
|
92
|
-
action="login"
|
|
93
|
-
checkFn={axios.get}
|
|
94
|
-
onClose={handleClose}
|
|
95
|
-
onSuccess={handleSuccess}
|
|
96
|
-
messages={{
|
|
97
|
-
title: '登录我的应用',
|
|
98
|
-
scan: '请使用您的 DID 钱包扫描二维码',
|
|
99
|
-
confirm: '在您的钱包上确认登录',
|
|
100
|
-
success: '您已成功登录!',
|
|
101
|
-
}}
|
|
102
|
-
webWalletUrl={webWalletUrl}
|
|
103
|
-
/>
|
|
104
|
-
</SessionProvider>
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export default App;
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
这个例子展示了如何仅用几个组件来管理用户会话和触发登录过程。
|
|
112
|
-
|
|
113
|
-
### 后续步骤
|
|
114
|
-
|
|
115
|
-
现在您对该库有了基本的了解,可以开始更深入地学习了。
|
|
116
|
-
|
|
117
|
-
<x-card data-title="开始使用" data-href="/getting-started" data-icon="lucide:rocket" data-cta="开始构建">
|
|
118
|
-
遵循我们的分步指南,从零开始将 DID Connect 集成到您自己的应用程序中。
|
|
119
|
-
</x-card>
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# Address
|
|
2
|
-
|
|
3
|
-
`Address`コンポーネントは、分散型識別子(DID)アドレスをクリーンで読みやすく、ユーザーフレンドリーな形式で表示するために設計された特殊なUI要素です。DIDに典型的な長い文字列を、短縮や簡単なコピーのオプションを提供することで賢く処理し、全体的なユーザーエクスペリエンスを向上させます。
|
|
4
|
-
|
|
5
|
-
このコンポーネントは`@arcblock/ux/lib/Address`からの単純な再エクスポートであり、DID Connectエコシステム内でアドレスを表示するための一貫した方法を提供します。
|
|
6
|
-
|
|
7
|
-
## インポート方法
|
|
8
|
-
|
|
9
|
-
`Address`コンポーネントを使用するには、ライブラリ内の特定のモジュールパスからインポートします。
|
|
10
|
-
|
|
11
|
-
```javascript Import icon=logos:javascript
|
|
12
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## 基本的な使用法
|
|
16
|
-
|
|
17
|
-
コンポーネントにDID文字列を子として渡すだけで、完全なアドレスをレンダリングできます。
|
|
18
|
-
|
|
19
|
-
```jsx Basic Address Display icon=logos:react
|
|
20
|
-
import React from 'react';
|
|
21
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
22
|
-
|
|
23
|
-
function UserProfile() {
|
|
24
|
-
const userDid = 'z1Zg2a5Vw2fA2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t';
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div>
|
|
28
|
-
<h4>User DID:</h4>
|
|
29
|
-
<Address>{userDid}</Address>
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## 機能
|
|
36
|
-
|
|
37
|
-
`Address`コンポーネントには、使いやすさを向上させるためのいくつかの便利な機能が含まれています。
|
|
38
|
-
|
|
39
|
-
### 短縮
|
|
40
|
-
|
|
41
|
-
長いDIDはUIを乱雑にする可能性があります。`shorten`プロパティを使用して、アドレスの短縮版を表示し、先頭と末尾の文字のみを表示します。これは、リストやコンパクトなプロファイルビューに不可欠です。
|
|
42
|
-
|
|
43
|
-
### クリップボードにコピー
|
|
44
|
-
|
|
45
|
-
`copyable`プロパティを追加すると、コンポーネントはアドレスの横にコピーアイコンをレンダリングします。このアイコンをクリックすると、完全なDIDがユーザーのクリップボードにコピーされ、便利なワンクリックアクションが提供されます。
|
|
46
|
-
|
|
47
|
-
## Props
|
|
48
|
-
|
|
49
|
-
`Address`コンポーネントは以下のpropsを受け入れます:
|
|
50
|
-
|
|
51
|
-
<x-field-group>
|
|
52
|
-
<x-field data-name="children" data-type="string" data-required="true">
|
|
53
|
-
<x-field-desc markdown>表示したいDIDアドレス文字列。</x-field-desc>
|
|
54
|
-
</x-field>
|
|
55
|
-
<x-field data-name="shorten" data-type="boolean" data-default="false" data-required="false">
|
|
56
|
-
<x-field-desc markdown>`true`の場合、アドレスはよりコンパクトな形式(例:`z1Zg2a...s0t`)に短縮されます。</x-field-desc>
|
|
57
|
-
</x-field>
|
|
58
|
-
<x-field data-name="copyable" data-type="boolean" data-default="false" data-required="false">
|
|
59
|
-
<x-field-desc markdown>`true`の場合、コピーアイコンが表示され、ユーザーはワンクリックで完全なアドレスをクリップボードにコピーできます。</x-field-desc>
|
|
60
|
-
</x-field>
|
|
61
|
-
<x-field data-name="responsive" data-type="boolean" data-default="true" data-required="false">
|
|
62
|
-
<x-field-desc markdown>`true`の場合、コンポーネントは利用可能な幅に基づいてアドレスを自動的に短縮し、レイアウトを崩さずにコンテナ内に収まるようにします。</x-field-desc>
|
|
63
|
-
</x-field>
|
|
64
|
-
</x-field-group>
|
|
65
|
-
|
|
66
|
-
## 例
|
|
67
|
-
|
|
68
|
-
以下は`Address`コンポーネントの一般的な使用例です。
|
|
69
|
-
|
|
70
|
-
### 短縮およびコピー可能なアドレス
|
|
71
|
-
|
|
72
|
-
これは最も一般的な設定で、ほとんどのUIに適したコンパクトで機能的な表示を提供します。
|
|
73
|
-
|
|
74
|
-
```jsx Shortened and Copyable icon=logos:react
|
|
75
|
-
import React from 'react';
|
|
76
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
77
|
-
|
|
78
|
-
function UserCard({ did }) {
|
|
79
|
-
return (
|
|
80
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
81
|
-
<span>DID:</span>
|
|
82
|
-
<Address shorten copyable>
|
|
83
|
-
{did}
|
|
84
|
-
</Address>
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Avatarとの使用
|
|
91
|
-
|
|
92
|
-
`Address`コンポーネントは、`Avatar`コンポーネントと並行して使用することで、ユーザープロファイル要素を構築するのに最適です。
|
|
93
|
-
|
|
94
|
-
```jsx Profile Header icon=logos:react
|
|
95
|
-
import React from 'react';
|
|
96
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
97
|
-
import Avatar from '@arcblock/did-connect-react/lib/Avatar';
|
|
98
|
-
import { useSession } from '@arcblock/did-connect-react';
|
|
99
|
-
|
|
100
|
-
function ProfileHeader() {
|
|
101
|
-
const { session } = useSession();
|
|
102
|
-
|
|
103
|
-
if (!session.user) {
|
|
104
|
-
return <p>Please log in.</p>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
|
|
109
|
-
<Avatar did={session.user.did} />
|
|
110
|
-
<div>
|
|
111
|
-
<strong>{session.user.name}</strong>
|
|
112
|
-
<Address shorten copyable>
|
|
113
|
-
{session.user.did}
|
|
114
|
-
</Address>
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
ユーザーアドレスの表示方法を学んだので、次はプロフィール写真の表示方法を学びたいかもしれません。[Avatar](./ui-components-avatar.md)コンポーネントのドキュメントで詳細を確認してください。
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# Address
|
|
2
|
-
|
|
3
|
-
The `Address` component is a specialized UI element designed to display Decentralized Identifier (DID) addresses in a clean, readable, and user-friendly format. It intelligently handles the long strings typical of DIDs by providing options for shortening and easy copying, enhancing the overall user experience.
|
|
4
|
-
|
|
5
|
-
This component is a simple re-export from `@arcblock/ux/lib/Address`, providing a consistent way to display addresses within the DID Connect ecosystem.
|
|
6
|
-
|
|
7
|
-
## How to Import
|
|
8
|
-
|
|
9
|
-
To use the `Address` component, import it from its specific module path within the library.
|
|
10
|
-
|
|
11
|
-
```javascript Import icon=logos:javascript
|
|
12
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Basic Usage
|
|
16
|
-
|
|
17
|
-
Simply pass the DID string as a child to the component to render the full address.
|
|
18
|
-
|
|
19
|
-
```jsx Basic Address Display icon=logos:react
|
|
20
|
-
import React from 'react';
|
|
21
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
22
|
-
|
|
23
|
-
function UserProfile() {
|
|
24
|
-
const userDid = 'z1Zg2a5Vw2fA2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t';
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div>
|
|
28
|
-
<h4>User DID:</h4>
|
|
29
|
-
<Address>{userDid}</Address>
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Features
|
|
36
|
-
|
|
37
|
-
The `Address` component includes several helpful features to improve usability.
|
|
38
|
-
|
|
39
|
-
### Shortening
|
|
40
|
-
|
|
41
|
-
Long DIDs can clutter the UI. Use the `shorten` prop to display a truncated version of the address, showing only the beginning and end characters. This is essential for lists or compact profile views.
|
|
42
|
-
|
|
43
|
-
### Copy to Clipboard
|
|
44
|
-
|
|
45
|
-
By adding the `copyable` prop, the component will render a copy icon next to the address. Clicking this icon copies the full DID to the user's clipboard, providing a convenient one-click action.
|
|
46
|
-
|
|
47
|
-
## Props
|
|
48
|
-
|
|
49
|
-
The `Address` component accepts the following props:
|
|
50
|
-
|
|
51
|
-
<x-field-group>
|
|
52
|
-
<x-field data-name="children" data-type="string" data-required="true">
|
|
53
|
-
<x-field-desc markdown>The DID address string that you want to display.</x-field-desc>
|
|
54
|
-
</x-field>
|
|
55
|
-
<x-field data-name="shorten" data-type="boolean" data-default="false" data-required="false">
|
|
56
|
-
<x-field-desc markdown>If `true`, the address will be shortened to a more compact format (e.g., `z1Zg2a...s0t`).</x-field-desc>
|
|
57
|
-
</x-field>
|
|
58
|
-
<x-field data-name="copyable" data-type="boolean" data-default="false" data-required="false">
|
|
59
|
-
<x-field-desc markdown>If `true`, a copy icon is displayed, allowing users to copy the full address to their clipboard with a single click.</x-field-desc>
|
|
60
|
-
</x-field>
|
|
61
|
-
<x-field data-name="responsive" data-type="boolean" data-default="true" data-required="false">
|
|
62
|
-
<x-field-desc markdown>When `true`, the component will automatically shorten the address based on the available width, ensuring it fits within its container without breaking the layout.</x-field-desc>
|
|
63
|
-
</x-field>
|
|
64
|
-
</x-field-group>
|
|
65
|
-
|
|
66
|
-
## Examples
|
|
67
|
-
|
|
68
|
-
Here are some common use cases for the `Address` component.
|
|
69
|
-
|
|
70
|
-
### Shortened and Copyable Address
|
|
71
|
-
|
|
72
|
-
This is the most common configuration, providing a compact and functional display suitable for most UIs.
|
|
73
|
-
|
|
74
|
-
```jsx Shortened and Copyable icon=logos:react
|
|
75
|
-
import React from 'react';
|
|
76
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
77
|
-
|
|
78
|
-
function UserCard({ did }) {
|
|
79
|
-
return (
|
|
80
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
81
|
-
<span>DID:</span>
|
|
82
|
-
<Address shorten copyable>
|
|
83
|
-
{did}
|
|
84
|
-
</Address>
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Usage with Avatar
|
|
91
|
-
|
|
92
|
-
The `Address` component works great alongside the `Avatar` component to build user profile elements.
|
|
93
|
-
|
|
94
|
-
```jsx Profile Header icon=logos:react
|
|
95
|
-
import React from 'react';
|
|
96
|
-
import Address from '@arcblock/did-connect-react/lib/Address';
|
|
97
|
-
import Avatar from '@arcblock/did-connect-react/lib/Avatar';
|
|
98
|
-
import { useSession } from '@arcblock/did-connect-react';
|
|
99
|
-
|
|
100
|
-
function ProfileHeader() {
|
|
101
|
-
const { session } = useSession();
|
|
102
|
-
|
|
103
|
-
if (!session.user) {
|
|
104
|
-
return <p>Please log in.</p>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
|
|
109
|
-
<Avatar did={session.user.did} />
|
|
110
|
-
<div>
|
|
111
|
-
<strong>{session.user.name}</strong>
|
|
112
|
-
<Address shorten copyable>
|
|
113
|
-
{session.user.did}
|
|
114
|
-
</Address>
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Now that you know how to display user addresses, you might want to learn how to display their profile pictures. Check out the [Avatar](./ui-components-avatar.md) component documentation for more details.
|