@arcblock/did-connect-react 3.1.40 → 3.1.42

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 (81) hide show
  1. package/.aigne/doc-smith/config.yaml +83 -0
  2. package/.aigne/doc-smith/output/structure-plan.json +197 -0
  3. package/.aigne/doc-smith/upload-cache.yaml +168 -0
  4. package/docs/_sidebar.md +18 -0
  5. package/docs/advanced-authentication-methods.ja.md +261 -0
  6. package/docs/advanced-authentication-methods.md +261 -0
  7. package/docs/advanced-authentication-methods.zh-TW.md +261 -0
  8. package/docs/advanced-authentication-methods.zh.md +261 -0
  9. package/docs/advanced-utilities.ja.md +132 -0
  10. package/docs/advanced-utilities.md +132 -0
  11. package/docs/advanced-utilities.zh-TW.md +132 -0
  12. package/docs/advanced-utilities.zh.md +132 -0
  13. package/docs/advanced.ja.md +95 -0
  14. package/docs/advanced.md +95 -0
  15. package/docs/advanced.zh-TW.md +95 -0
  16. package/docs/advanced.zh.md +95 -0
  17. package/docs/api-reference.ja.md +178 -0
  18. package/docs/api-reference.md +178 -0
  19. package/docs/api-reference.zh-TW.md +178 -0
  20. package/docs/api-reference.zh.md +178 -0
  21. package/docs/core-components-did-connect.ja.md +214 -0
  22. package/docs/core-components-did-connect.md +213 -0
  23. package/docs/core-components-did-connect.zh-TW.md +214 -0
  24. package/docs/core-components-did-connect.zh.md +213 -0
  25. package/docs/core-components-session-provider.ja.md +239 -0
  26. package/docs/core-components-session-provider.md +239 -0
  27. package/docs/core-components-session-provider.zh-TW.md +239 -0
  28. package/docs/core-components-session-provider.zh.md +239 -0
  29. package/docs/core-components.ja.md +16 -0
  30. package/docs/core-components.md +16 -0
  31. package/docs/core-components.zh-TW.md +16 -0
  32. package/docs/core-components.zh.md +16 -0
  33. package/docs/getting-started.ja.md +138 -0
  34. package/docs/getting-started.md +138 -0
  35. package/docs/getting-started.zh-TW.md +138 -0
  36. package/docs/getting-started.zh.md +138 -0
  37. package/docs/hooks-use-connect.ja.md +214 -0
  38. package/docs/hooks-use-connect.md +214 -0
  39. package/docs/hooks-use-connect.zh-TW.md +214 -0
  40. package/docs/hooks-use-connect.zh.md +214 -0
  41. package/docs/hooks-use-did.ja.md +107 -0
  42. package/docs/hooks-use-did.md +107 -0
  43. package/docs/hooks-use-did.zh-TW.md +107 -0
  44. package/docs/hooks-use-did.zh.md +107 -0
  45. package/docs/hooks-use-oauth-passkey.ja.md +188 -0
  46. package/docs/hooks-use-oauth-passkey.md +188 -0
  47. package/docs/hooks-use-oauth-passkey.zh-TW.md +188 -0
  48. package/docs/hooks-use-oauth-passkey.zh.md +188 -0
  49. package/docs/hooks.ja.md +23 -0
  50. package/docs/hooks.md +23 -0
  51. package/docs/hooks.zh-TW.md +23 -0
  52. package/docs/hooks.zh.md +23 -0
  53. package/docs/overview.ja.md +159 -0
  54. package/docs/overview.md +159 -0
  55. package/docs/overview.zh-TW.md +159 -0
  56. package/docs/overview.zh.md +160 -0
  57. package/docs/ui-components-address.ja.md +121 -0
  58. package/docs/ui-components-address.md +121 -0
  59. package/docs/ui-components-address.zh-TW.md +121 -0
  60. package/docs/ui-components-address.zh.md +121 -0
  61. package/docs/ui-components-avatar.ja.md +65 -0
  62. package/docs/ui-components-avatar.md +65 -0
  63. package/docs/ui-components-avatar.zh-TW.md +65 -0
  64. package/docs/ui-components-avatar.zh.md +65 -0
  65. package/docs/ui-components-button.ja.md +99 -0
  66. package/docs/ui-components-button.md +99 -0
  67. package/docs/ui-components-button.zh-TW.md +99 -0
  68. package/docs/ui-components-button.zh.md +99 -0
  69. package/docs/ui-components-logo.ja.md +52 -0
  70. package/docs/ui-components-logo.md +52 -0
  71. package/docs/ui-components-logo.zh-TW.md +52 -0
  72. package/docs/ui-components-logo.zh.md +52 -0
  73. package/docs/ui-components.ja.md +57 -0
  74. package/docs/ui-components.md +57 -0
  75. package/docs/ui-components.zh-TW.md +57 -0
  76. package/docs/ui-components.zh.md +57 -0
  77. package/glossary.md +1 -0
  78. package/lib/package.json.js +1 -1
  79. package/package.json +5 -5
  80. package/src/Session/hooks/use-federated.js +3 -0
  81. package/src/Session/libs/federated.js +3 -0
@@ -0,0 +1,188 @@
1
+ # useOAuth & usePasskey
2
+
3
+ `DidConnect` 组件和 `useConnect` hook 为所有身份验证方法提供了全面的、预构建的用户界面,但你可能需要构建自定义的身份验证流程。`useOAuth` 和 `usePasskey` hook 提供了对社交登录 (OAuth) 和无密码身份验证 (Passkey) 底层逻辑的直接访问。
4
+
5
+ 这些 hook 是创建定制化用户体验的强大工具。它们依赖于各自的上下文提供程序 `OAuthProvider` 和 `PasskeyProvider`,这些提供程序通常包含在主 `SessionProvider` 中。有关会话管理的更多信息,请参阅 [SessionProvider 文档](./core-components-session-provider.md)。
6
+
7
+ ## useOAuth
8
+
9
+ `useOAuth` hook 提供了用于处理第三方社交登录流程的函数和状态。
10
+
11
+ ### 导入
12
+
13
+ ```javascript icon=logos:javascript
14
+ import { useOAuth } from '@arcblock/did-connect-react/lib/OAuth';
15
+ ```
16
+
17
+ ### 返回值
18
+
19
+ 该 hook 返回一个包含以下属性和方法的对象:
20
+
21
+ <x-field-group>
22
+ <x-field data-name="loginOAuth" data-type="function" data-required="true">
23
+ <x-field-desc markdown>使用指定的 OAuth 提供商启动登录流程。它会打开一个弹出窗口供用户授权,并返回一个解析为登录结果的 promise。</x-field-desc>
24
+ </x-field>
25
+ <x-field data-name="bindOAuth" data-type="function" data-required="true">
26
+ <x-field-desc markdown>将新的 OAuth 帐户绑定到当前登录用户的会话。</x-field-desc>
27
+ </x-field>
28
+ <x-field data-name="unbindOAuth" data-type="function" data-required="true">
29
+ <x-field-desc markdown>从当前用户的会话中解绑 OAuth 帐户。</x-field-desc>
30
+ </x-field>
31
+ <x-field data-name="getOAuthConfigList" data-type="function" data-required="true">
32
+ <x-field-desc markdown>从 Blocklet 设置中获取已启用和已配置的 OAuth 提供商列表。返回一个解析为提供商配置对象数组的 promise。</x-field-desc>
33
+ </x-field>
34
+ <x-field data-name="switchOAuthPassport" data-type="function" data-required="true">
35
+ <x-field-desc markdown>启动一个流程,用于在同一身份的不同已连接帐户(通行证)之间切换。</x-field-desc>
36
+ </x-field>
37
+ <x-field data-name="bindAuthLoading" data-type="boolean" data-required="true">
38
+ <x-field-desc markdown>一个布尔标志,当 `bindOAuth` 操作正在进行时为 `true`。</x-field-desc>
39
+ </x-field>
40
+ <x-field data-name="unbindAuthLoading" data-type="boolean" data-required="true">
41
+ <x-field-desc markdown>一个布尔标志,当 `unbindOAuth` 操作正在进行时为 `true`。</x-field-desc>
42
+ </x-field>
43
+ <x-field data-name="oauthState" data-type="object" data-required="true">
44
+ <x-field-desc markdown>一个包含身份验证过程实时状态的对象。</x-field-desc>
45
+ <x-field data-name="loading" data-type="boolean" data-desc="如果 OAuth 操作正在进行,则为 True。"></x-field>
46
+ <x-field data-name="error" data-type="string" data-desc="如果操作失败,则包含错误消息。"></x-field>
47
+ <x-field data-name="status" data-type="string" data-desc="流程的当前状态(例如,'scanned', 'succeed', 'error')。"></x-field>
48
+ </x-field>
49
+ </x-field-group>
50
+
51
+ ### 用法示例
52
+
53
+ 以下是如何构建自定义社交登录组件的示例。
54
+
55
+ ```jsx CustomSocialLogin.jsx icon=logos:react
56
+ import React, { useEffect, useState } from 'react';
57
+ import { useOAuth } from '@arcblock/did-connect-react/lib/OAuth';
58
+ import { useSession } from '@arcblock/did-connect-react/lib/Session';
59
+
60
+ export default function CustomSocialLogin() {
61
+ const { loginOAuth, getOAuthConfigList } = useOAuth();
62
+ const { session } = useSession();
63
+ const [providers, setProviders] = useState([]);
64
+ const [loading, setLoading] = useState(false);
65
+ const [error, setError] = useState('');
66
+
67
+ useEffect(() => {
68
+ // 组件挂载时获取可用的 OAuth 提供商列表
69
+ getOAuthConfigList().then(setProviders).catch(console.error);
70
+ }, [getOAuthConfigList]);
71
+
72
+ const handleLogin = async (provider) => {
73
+ setLoading(true);
74
+ setError('');
75
+ try {
76
+ const result = await loginOAuth({ provider: provider.provider });
77
+ // 成功登录后,会话将由 SessionProvider 自动更新。
78
+ console.log('Login successful:', result);
79
+ // 你可能需要在此处刷新会话或重定向用户。
80
+ } catch (err) {
81
+ setError(err.message);
82
+ console.error('Login failed:', err);
83
+ } finally {
84
+ setLoading(false);
85
+ }
86
+ };
87
+
88
+ if (session.user) {
89
+ return <div>您已登录为 {session.user.name}。</div>;
90
+ }
91
+
92
+ if (providers.length === 0) {
93
+ return <div>未配置社交登录方法。</div>;
94
+ }
95
+
96
+ return (
97
+ <div>
98
+ <h3>使用社交媒体登录</h3>
99
+ {providers.map((p) => (
100
+ <button key={p.provider} onClick={() => handleLogin(p)} disabled={loading}>
101
+ {loading ? '登录中...' : `使用 ${p.provider} 登录`}
102
+ </button>
103
+ ))}
104
+ {error && <p style={{ color: 'red' }}>{error}</p>}
105
+ </div>
106
+ );
107
+ }
108
+ ```
109
+
110
+ ## usePasskey
111
+
112
+ `usePasskey` hook 提供了使用 WebAuthn (Passkeys) 处理无密码身份验证的函数和状态。
113
+
114
+ ### 导入
115
+
116
+ ```javascript icon=logos:javascript
117
+ import { usePasskey } from '@arcblock/did-connect-react/lib/Passkey';
118
+ ```
119
+
120
+ ### 返回值
121
+
122
+ 该 hook 返回一个包含以下属性和方法的对象:
123
+
124
+ <x-field-group>
125
+ <x-field data-name="loginPasskey" data-type="function" data-required="true">
126
+ <x-field-desc markdown>使用现有的 Passkey 启动登录流程。它会触发浏览器的原生 WebAuthn 身份验证提示。</x-field-desc>
127
+ </x-field>
128
+ <x-field data-name="connectPasskey" data-type="function" data-required="true">
129
+ <x-field-desc markdown>启动一个流程,以创建新的 Passkey 并将其绑定到当前用户的会话。</x-field-desc>
130
+ </x-field>
131
+ <x-field data-name="disconnectPasskey" data-type="function" data-required="true">
132
+ <x-field-desc markdown>成功验证后,从当前用户的会话中解绑 Passkey。</x-field-desc>
133
+ </x-field>
134
+ <x-field data-name="switchPassport" data-type="function" data-required="true">
135
+ <x-field-desc markdown>启动一个流程,用于在不同的已连接帐户(通行证)之间切换。</x-field-desc>
136
+ </x-field>
137
+ <x-field data-name="connecting" data-type="boolean" data-required="true">
138
+ <x-field-desc markdown>一个布尔标志,当 `connectPasskey` 操作正在进行时为 `true`。</x-field-desc>
139
+ </x-field>
140
+ <x-field data-name="disconnecting" data-type="boolean" data-required="true">
141
+ <x-field-desc markdown>一个布尔标志,当 `disconnectPasskey` 操作正在进行时为 `true`。</x-field-desc>
142
+ </x-field>
143
+ <x-field data-name="passkeyState" data-type="object" data-required="true">
144
+ <x-field-desc markdown>一个包含 Passkey 操作实时状态的对象。</x-field-desc>
145
+ <x-field data-name="loading" data-type="boolean" data-desc="如果 Passkey 操作正在进行,则为 True。"></x-field>
146
+ <x-field data-name="creating" data-type="boolean" data-desc="在 Passkey 创建阶段为 True。"></x-field>
147
+ <x-field data-name="verifying" data-type="boolean" data-desc="在 Passkey 验证阶段为 True。"></x-field>
148
+ <x-field data-name="error" data-type="string" data-desc="如果操作失败,则包含错误消息。"></x-field>
149
+ <x-field data-name="status" data-type="string" data-desc="流程的当前状态(例如,'scanned', 'succeed', 'error')。"></x-field>
150
+ </x-field>
151
+ </x-field-group>
152
+
153
+ ### 用法示例
154
+
155
+ 以下是如何创建“使用 Passkey 登录”按钮的示例。
156
+
157
+ ```jsx PasskeyLoginButton.jsx icon=logos:react
158
+ import React, { useState } from 'react';
159
+ import { usePasskey } from '@arcblock/did-connect-react/lib/Passkey';
160
+
161
+ export default function PasskeyLoginButton() {
162
+ const { loginPasskey, passkeyState } = usePasskey();
163
+ const [error, setError] = useState('');
164
+
165
+ const handleLogin = async () => {
166
+ setError('');
167
+ try {
168
+ const result = await loginPasskey();
169
+ console.log('Passkey login successful:', result);
170
+ // 会话将由 SessionProvider 自动更新。
171
+ } catch (err) {
172
+ setError(err.message);
173
+ console.error('Passkey login failed:', err);
174
+ }
175
+ };
176
+
177
+ return (
178
+ <div>
179
+ <button onClick={handleLogin} disabled={passkeyState.loading}>
180
+ {passkeyState.loading ? '验证中...' : '使用 Passkey 登录'}
181
+ </button>
182
+ {error && <p style={{ color: 'red' }}>{error}</p>}
183
+ </div>
184
+ );
185
+ }
186
+ ```
187
+
188
+ 这些 hook 提供了将 DID Connect 强大的身份验证功能以完全自定义的 UI 集成到应用程序任何部分的灵活性。要了解如何以编程方式控制预构建的 `DidConnect` 模态框,请继续阅读 [useConnect hook 文档](./hooks-use-connect.md)。
@@ -0,0 +1,23 @@
1
+ # フック
2
+
3
+ `@arcblock/did-connect-react` ライブラリは、プログラムによる制御と柔軟なデータアクセスを提供する強力なReactフックのセットを提供します。[SessionProvider](./core-components-session-provider.md) は便利なコンテキストベースのアプローチを提供しますが、フックは複雑なUIや高度なユースケースに必要なきめ細かい制御を提供します。
4
+
5
+ これらのフックを使用すると、接続フローの管理、ユーザーデータへのアクセス、および `SessionProvider` のスコープ内の任意のコンポーネントからさまざまな認証方法を統合できます。
6
+
7
+ <x-cards data-columns="3">
8
+ <x-card data-title="useConnect" data-icon="lucide:plug-zap" data-href="/hooks/use-connect">
9
+ DID Connect UIモーダルをプログラムで開閉・管理します。これは接続フローを制御するためのコアフックです。
10
+ </x-card>
11
+ <x-card data-title="useDid" data-icon="lucide:user-check" data-href="/hooks/use-did">
12
+ セッションから認証されたユーザーのDID、プロフィール、ウォレット情報に簡単にアクセスして作業するための便利なユーティリティフックです。
13
+ </x-card>
14
+ <x-card data-title="useOAuth & usePasskey" data-icon="lucide:key-round" data-href="/hooks/use-oauth-passkey">
15
+ モダンで代替的な認証方法を統合します。`useOAuth` はソーシャルログインを処理し、`usePasskey` は安全なパスワードレス認証を可能にします。
16
+ </x-card>
17
+ </x-cards>
18
+
19
+ ## 概要
20
+
21
+ これらのフックを活用することで、高度にカスタマイズされたシームレスなユーザーエクスペリエンスを構築できます。まず `useConnect` を調べてログインフローをトリガーする方法を理解し、次に `useDid` がユーザー情報を表示するのにどのように役立つかを確認してください。
22
+
23
+ さらに深く掘り下げますか?上記のフックから選択して詳細を学ぶか、[UIコンポーネント](./ui-components.md)セクションに進んでユーザーデータの表示方法を確認してください。
package/docs/hooks.md ADDED
@@ -0,0 +1,23 @@
1
+ # Hooks
2
+
3
+ The `@arcblock/did-connect-react` library offers a powerful set of React hooks that provide programmatic control and flexible data access. While the [SessionProvider](./core-components-session-provider.md) offers a convenient context-based approach, hooks give you the fine-grained control needed for complex UIs and advanced use cases.
4
+
5
+ These hooks allow you to manage the connection flow, access user data, and integrate various authentication methods from any component within the `SessionProvider`'s scope.
6
+
7
+ <x-cards data-columns="3">
8
+ <x-card data-title="useConnect" data-icon="lucide:plug-zap" data-href="/hooks/use-connect">
9
+ Programmatically open, close, and manage the DID Connect UI modal. This is the core hook for controlling the connection flow.
10
+ </x-card>
11
+ <x-card data-title="useDid" data-icon="lucide:user-check" data-href="/hooks/use-did">
12
+ A convenient utility hook to easily access and work with the authenticated user's DID, profile, and wallet information from the session.
13
+ </x-card>
14
+ <x-card data-title="useOAuth & usePasskey" data-icon="lucide:key-round" data-href="/hooks/use-oauth-passkey">
15
+ Integrate modern, alternative authentication methods. `useOAuth` handles social logins, while `usePasskey` enables secure, passwordless authentication.
16
+ </x-card>
17
+ </x-cards>
18
+
19
+ ## Summary
20
+
21
+ By leveraging these hooks, you can build highly customized and seamless user experiences. Start by exploring `useConnect` to understand how to trigger the login flow, then see how `useDid` can help you display user information.
22
+
23
+ Ready to dive deeper? Choose a hook from above to learn more, or proceed to the [UI Components](./ui-components.md) section to see how you can display user data.
@@ -0,0 +1,23 @@
1
+ # Hooks
2
+
3
+ `@arcblock/did-connect-react` 函式庫提供了一組強大的 React hooks,可提供程式化控制和靈活的資料存取。雖然 [SessionProvider](./core-components-session-provider.md) 提供了一種方便的基於上下文的方法,但 hooks 為您提供了複雜 UI 和進階用例所需的精細控制。
4
+
5
+ 這些 hooks 讓您可以在 `SessionProvider` 作用域內的任何元件中管理連接流程、存取使用者資料以及整合各種身份驗證方法。
6
+
7
+ <x-cards data-columns="3">
8
+ <x-card data-title="useConnect" data-icon="lucide:plug-zap" data-href="/hooks/use-connect">
9
+ 以程式化方式開啟、關閉和管理 DID Connect UI 互動視窗。這是控制連接流程的核心 hook。
10
+ </x-card>
11
+ <x-card data-title="useDid" data-icon="lucide:user-check" data-href="/hooks/use-did">
12
+ 一個方便的實用工具 hook,可輕鬆從 session 中存取和使用通過身份驗證的使用者的 DID、個人資料和錢包資訊。
13
+ </x-card>
14
+ <x-card data-title="useOAuth & usePasskey" data-icon="lucide:key-round" data-href="/hooks/use-oauth-passkey">
15
+ 整合現代的替代身份驗證方法。`useOAuth` 處理社交登入,而 `usePasskey` 則啟用安全、無密碼的身份驗證。
16
+ </x-card>
17
+ </x-cards>
18
+
19
+ ## 總結
20
+
21
+ 透過利用這些 hooks,您可以建構高度客製化和無縫的使用者體驗。首先探索 `useConnect` 以了解如何觸發登入流程,然後看看 `useDid` 如何幫助您顯示使用者資訊。
22
+
23
+ 準備好深入了解了嗎?從上面選擇一個 hook 以了解更多資訊,或前往 [UI Components](./ui-components.md) 部分查看如何顯示使用者資料。
@@ -0,0 +1,23 @@
1
+ # Hooks
2
+
3
+ `@arcblock/did-connect-react` 库提供了一套功能强大的 React Hooks,可实现编程控制和灵活的数据访问。虽然 [SessionProvider](./core-components-session-provider.md) 提供了一种方便的基于上下文的方法,但 Hooks 为您提供了复杂 UI 和高级用例所需的精细控制。
4
+
5
+ 这些 Hooks 允许您从 `SessionProvider` 作用域内的任何组件管理连接流程、访问用户数据并集成各种身份验证方法。
6
+
7
+ <x-cards data-columns="3">
8
+ <x-card data-title="useConnect" data-icon="lucide:plug-zap" data-href="/hooks/use-connect">
9
+ 以编程方式打开、关闭和管理 DID Connect UI 模态框。这是控制连接流程的核心 Hook。
10
+ </x-card>
11
+ <x-card data-title="useDid" data-icon="lucide:user-check" data-href="/hooks/use-did">
12
+ 一个方便的实用工具 Hook,可轻松访问和使用会话中经过身份验证的用户的 DID、个人资料和钱包信息。
13
+ </x-card>
14
+ <x-card data-title="useOAuth & usePasskey" data-icon="lucide:key-round" data-href="/hooks/use-oauth-passkey">
15
+ 集成现代的替代身份验证方法。`useOAuth` 处理社交登录,而 `usePasskey` 则实现安全的无密码身份验证。
16
+ </x-card>
17
+ </x-cards>
18
+
19
+ ## 摘要
20
+
21
+ 通过利用这些 Hooks,您可以构建高度定制化和无缝的用户体验。首先探索 `useConnect` 以了解如何触发登录流程,然后看看 `useDid` 如何帮助您显示用户信息。
22
+
23
+ 准备好深入了解了吗?从上面选择一个 Hook 以了解更多信息,或继续前往 [UI 组件](./ui-components.md) 部分查看如何显示用户数据。
@@ -0,0 +1,159 @@
1
+ # 概要
2
+
3
+ `@arcblock/did-connect-react` ライブラリは、Webアプリケーションに分散型ID(DID)機能をシームレスに統合するために設計された、包括的なReactコンポーネントとフックのセットを提供します。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
+ QRコードのスキャンと接続プロセス全体を処理するための、事前に構築されたカスタマイズ可能なモーダルである `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
+ `Avatar`、`Address`、`Button` のような補足的なUIコンポーネントのコレクションで、ユーザーのID情報を一貫して表示します。
21
+ </x-card>
22
+ </x-cards>
23
+
24
+ ### コアアーキテクチャ
25
+
26
+ このライブラリは、ユーザーのセッション状態を管理する中央の `SessionProvider` を中心に展開します。`Button` のようなUIコンポーネントは `DidConnect` モーダルをトリガーし、ユーザーのDID Walletとの安全なQRコードベースの対話を処理します。接続が完了すると、セッションが更新され、アプリケーションのUIがそれに応じて反応します。
27
+
28
+ ```d2 Basic Authentication Flow
29
+ direction: down
30
+
31
+ User: {
32
+ shape: c4-person
33
+ }
34
+
35
+ Your-Application: {
36
+ label: "あなたのReactアプリケーション"
37
+ shape: rectangle
38
+
39
+ SessionProvider: {
40
+ label: "SessionProvider\n(セッション状態を管理)"
41
+ shape: rectangle
42
+
43
+ App-Components: {
44
+ label: "あなたのアプリコンポーネント"
45
+ shape: rectangle
46
+
47
+ ConnectButton: {
48
+ label: "ConnectButton"
49
+ shape: rectangle
50
+ }
51
+ }
52
+
53
+ DidConnect-Modal: {
54
+ label: "DidConnectモーダル\n(QRコードフローを処理)"
55
+ shape: rectangle
56
+ }
57
+ }
58
+ }
59
+
60
+ DID-Wallet: {
61
+ label: "DID Wallet"
62
+ icon: "https://www.arcblock.io/image-bin/uploads/37198ddc4a0b9e91e5c1c821ab895a34.svg"
63
+ }
64
+
65
+ User -> Your-Application.SessionProvider.App-Components.ConnectButton: "1. ボタンをクリック"
66
+ Your-Application.SessionProvider.App-Components.ConnectButton -> Your-Application.SessionProvider.DidConnect-Modal: "2. モーダルを開く"
67
+ Your-Application.SessionProvider.DidConnect-Modal -> User: "3. QRコードを表示"
68
+ User -> DID-Wallet: "4. スキャンして承認"
69
+ DID-Wallet -> Your-Application.SessionProvider: "5. 接続を完了"
70
+ Your-Application.SessionProvider -> Your-Application.SessionProvider.App-Components: "6. セッション状態を更新"
71
+
72
+ ```
73
+
74
+ ### インストール
75
+
76
+ 始めるには、`yarn` または `npm` を使用してプロジェクトにライブラリを追加します。
77
+
78
+ ```shell Installation icon=lucide:download
79
+ # With yarn
80
+ yarn add @arcblock/did-connect-react
81
+
82
+ # With npm
83
+ npm install @arcblock/did-connect-react
84
+ ```
85
+
86
+ ### 仕組み:クイックルック
87
+
88
+ これは、ログインフローを設定する方法の最小限の例です。アプリケーションは `SessionProvider` でラップされ、`Button` を使用して `DidConnect` モーダルを切り替えます。
89
+
90
+ ```jsx App.js icon=logos:react
91
+ import React from 'react';
92
+ import axios from 'axios';
93
+ import { SessionProvider, SessionConsumer } from '@arcblock/did-connect-react/lib/Session';
94
+ import DidConnect from '@arcblock/did-connect-react/lib/Connect';
95
+ import Button from '@arcblock/did-connect-react/lib/Button';
96
+
97
+ const webWalletUrl = 'https://web.abtwallet.io/';
98
+
99
+ function App() {
100
+ const [isConnectOpen, setConnectOpen] = React.useState(false);
101
+
102
+ const handleClose = () => setConnectOpen(false);
103
+ const handleSuccess = () => {
104
+ // ログイン成功後にリダイレクトまたはUIを更新
105
+ window.location.reload();
106
+ };
107
+
108
+ return (
109
+ <SessionProvider serviceHost="/">
110
+ <div className="main-content">
111
+ <SessionConsumer>
112
+ {({ session }) => {
113
+ if (session.loading) {
114
+ return <div>セッションを読み込み中...</div>;
115
+ }
116
+
117
+ return session.user ? (
118
+ <div>
119
+ <h2>ようこそ、{session.user.did}さん!</h2>
120
+ <button onClick={() => session.logout()}>ログアウト</button>
121
+ </div>
122
+ ) : (
123
+ <Button onClick={() => setConnectOpen(true)}>ウォレットに接続</Button>
124
+ );
125
+ }}
126
+ </SessionConsumer>
127
+ </div>
128
+
129
+ <DidConnect
130
+ popup
131
+ open={isConnectOpen}
132
+ action="login"
133
+ checkFn={axios.get}
134
+ onClose={handleClose}
135
+ onSuccess={handleSuccess}
136
+ messages={{
137
+ title: 'マイアプリにログイン',
138
+ scan: 'DID WalletでQRコードをスキャンしてください',
139
+ confirm: 'ウォレットでログインを確認してください',
140
+ success: '正常にサインインしました!',
141
+ }}
142
+ webWalletUrl={webWalletUrl}
143
+ />
144
+ </SessionProvider>
145
+ );
146
+ }
147
+
148
+ export default App;
149
+ ```
150
+
151
+ この例は、わずか数個のコンポーネントでユーザーセッションを管理し、ログインプロセスをトリガーする方法を示しています。
152
+
153
+ ### 次のステップ
154
+
155
+ ライブラリの基本的な理解が得られたので、さらに深く掘り下げる準備ができました。
156
+
157
+ <x-card data-title="はじめに" data-href="/getting-started" data-icon="lucide:rocket" data-cta="ビルドを開始">
158
+ ステップバイステップのガイドに従って、DID Connectをゼロから独自のアプリケーションに統合します。
159
+ </x-card>
@@ -0,0 +1,159 @@
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
+ ```d2 Basic Authentication Flow
29
+ direction: down
30
+
31
+ User: {
32
+ shape: c4-person
33
+ }
34
+
35
+ Your-Application: {
36
+ label: "Your React Application"
37
+ shape: rectangle
38
+
39
+ SessionProvider: {
40
+ label: "SessionProvider\n(Manages session state)"
41
+ shape: rectangle
42
+
43
+ App-Components: {
44
+ label: "Your App Components"
45
+ shape: rectangle
46
+
47
+ ConnectButton: {
48
+ label: "ConnectButton"
49
+ shape: rectangle
50
+ }
51
+ }
52
+
53
+ DidConnect-Modal: {
54
+ label: "DidConnect Modal\n(Handles QR code flow)"
55
+ shape: rectangle
56
+ }
57
+ }
58
+ }
59
+
60
+ DID-Wallet: {
61
+ label: "DID Wallet"
62
+ icon: "https://www.arcblock.io/image-bin/uploads/37198ddc4a0b9e91e5c1c821ab895a34.svg"
63
+ }
64
+
65
+ User -> Your-Application.SessionProvider.App-Components.ConnectButton: "1. Clicks button"
66
+ Your-Application.SessionProvider.App-Components.ConnectButton -> Your-Application.SessionProvider.DidConnect-Modal: "2. Opens modal"
67
+ Your-Application.SessionProvider.DidConnect-Modal -> User: "3. Displays QR code"
68
+ User -> DID-Wallet: "4. Scans & approves"
69
+ DID-Wallet -> Your-Application.SessionProvider: "5. Completes connection"
70
+ Your-Application.SessionProvider -> Your-Application.SessionProvider.App-Components: "6. Updates session state"
71
+
72
+ ```
73
+
74
+ ### Installation
75
+
76
+ To get started, add the library to your project using `yarn` or `npm`.
77
+
78
+ ```shell Installation icon=lucide:download
79
+ # With yarn
80
+ yarn add @arcblock/did-connect-react
81
+
82
+ # With npm
83
+ npm install @arcblock/did-connect-react
84
+ ```
85
+
86
+ ### How It Works: A Quick Look
87
+
88
+ 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.
89
+
90
+ ```jsx App.js icon=logos:react
91
+ import React from 'react';
92
+ import axios from 'axios';
93
+ import { SessionProvider, SessionConsumer } from '@arcblock/did-connect-react/lib/Session';
94
+ import DidConnect from '@arcblock/did-connect-react/lib/Connect';
95
+ import Button from '@arcblock/did-connect-react/lib/Button';
96
+
97
+ const webWalletUrl = 'https://web.abtwallet.io/';
98
+
99
+ function App() {
100
+ const [isConnectOpen, setConnectOpen] = React.useState(false);
101
+
102
+ const handleClose = () => setConnectOpen(false);
103
+ const handleSuccess = () => {
104
+ // Redirect or update UI after successful login
105
+ window.location.reload();
106
+ };
107
+
108
+ return (
109
+ <SessionProvider serviceHost="/">
110
+ <div className="main-content">
111
+ <SessionConsumer>
112
+ {({ session }) => {
113
+ if (session.loading) {
114
+ return <div>Loading session...</div>;
115
+ }
116
+
117
+ return session.user ? (
118
+ <div>
119
+ <h2>Welcome, {session.user.did}!</h2>
120
+ <button onClick={() => session.logout()}>Logout</button>
121
+ </div>
122
+ ) : (
123
+ <Button onClick={() => setConnectOpen(true)}>Connect Wallet</Button>
124
+ );
125
+ }}
126
+ </SessionConsumer>
127
+ </div>
128
+
129
+ <DidConnect
130
+ popup
131
+ open={isConnectOpen}
132
+ action="login"
133
+ checkFn={axios.get}
134
+ onClose={handleClose}
135
+ onSuccess={handleSuccess}
136
+ messages={{
137
+ title: 'Login to My App',
138
+ scan: 'Scan QR code with your DID Wallet',
139
+ confirm: 'Confirm login on your wallet',
140
+ success: 'You have successfully signed in!',
141
+ }}
142
+ webWalletUrl={webWalletUrl}
143
+ />
144
+ </SessionProvider>
145
+ );
146
+ }
147
+
148
+ export default App;
149
+ ```
150
+
151
+ This example demonstrates how to manage user sessions and trigger the login process with just a few components.
152
+
153
+ ### Next Steps
154
+
155
+ Now that you have a basic understanding of the library, you're ready to dive deeper.
156
+
157
+ <x-card data-title="Getting Started" data-href="/getting-started" data-icon="lucide:rocket" data-cta="Start Building">
158
+ Follow our step-by-step guide to integrate DID Connect into your own application from scratch.
159
+ </x-card>