@powerhousedao/academy 5.1.0-staging.0 → 5.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +46 -1148
  2. package/blog/BeyondCommunication-ABlueprintForDevelopment.md +1 -2
  3. package/blog/TheChallengeOfChange.md +0 -1
  4. package/docs/academy/00-EthereumArgentinaHackathon.md +207 -0
  5. package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +27 -24
  6. package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +10 -155
  7. package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +35 -122
  8. package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +155 -178
  9. package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
  10. package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +22 -62
  11. package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
  12. package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
  13. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
  14. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +44 -75
  15. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +22 -28
  16. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +31 -28
  17. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +206 -211
  18. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +62 -176
  19. package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +0 -21
  20. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +319 -309
  21. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +0 -4
  22. package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +0 -4
  23. package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
  24. package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +35 -111
  25. package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +79 -195
  26. package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +241 -435
  27. package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +27 -388
  28. package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +7 -95
  29. package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
  30. package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +2 -6
  31. package/docs/academy/04-APIReferences/01-ReactHooks.md +501 -291
  32. package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +39 -7
  33. package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +65 -0
  34. package/docs/academy/05-Architecture/04-MovingBeyondCRUD +61 -0
  35. package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +24 -72
  36. package/docs/academy/08-Glossary.md +0 -7
  37. package/docusaurus.config.ts +3 -28
  38. package/package.json +1 -1
  39. package/sidebars.ts +13 -49
  40. package/src/css/custom.css +18 -26
  41. package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -425
  42. package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -557
  43. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/Modules.png +0 -0
  44. package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/images/VetraStudioDrive.png +0 -0
  45. package/docs/academy/02-MasteryTrack/05-Launch/05-DockerDeployment.md +0 -384
  46. package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
  47. package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
  48. package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  49. package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
  50. package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
  51. package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  52. package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
  53. package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
  54. package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
  55. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
  56. package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
  57. package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
  58. package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
  59. package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
  60. package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
  61. package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
  62. package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
  63. package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
  64. package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
  65. package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
  66. package/static/img/Vetra-logo-dark.svg +0 -11
  67. package/static/img/vetra-logo-light.svg +0 -11
  68. /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
  69. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
  70. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
  71. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
  72. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
  73. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
  74. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
  75. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
  76. /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /three-data-layers.png" → three-data-layers.png} +0 -0
@@ -1,957 +0,0 @@
1
- # API Reference
2
-
3
- Complete API reference for the Renown SDK.
4
-
5
- ## Table of Contents
6
-
7
- - [Components](#components)
8
- - [Hooks](#hooks)
9
- - [Functions](#functions)
10
- - [Types](#types)
11
- - [Classes](#classes)
12
- - [Constants](#constants)
13
-
14
- ## Components
15
-
16
- ### `RenownUserProvider`
17
-
18
- Central authentication provider that automatically initializes the Renown SDK.
19
-
20
- #### Props
21
-
22
- ```typescript
23
- interface RenownUserProviderProps {
24
- children: React.ReactNode
25
- renownUrl?: string
26
- networkId?: string
27
- chainId?: string
28
- loadingComponent?: React.ReactNode
29
- errorComponent?: (error: Error, retry: () => void) => React.ReactNode
30
- }
31
- ```
32
-
33
- | Prop | Type | Default | Description |
34
- |------|------|---------|-------------|
35
- | `children` | `React.ReactNode` | - | **Required.** Child components |
36
- | `renownUrl` | `string` | `'https://www.renown.id'` | Renown service URL |
37
- | `networkId` | `string` | `'eip155'` | Network identifier |
38
- | `chainId` | `string` | `'1'` | Chain identifier |
39
- | `loadingComponent` | `React.ReactNode` | undefined | Custom loading UI during initialization |
40
- | `errorComponent` | `(error, retry) => ReactNode` | undefined | Custom error UI if initialization fails |
41
-
42
- #### Example
43
-
44
- **Basic usage (auto-initializes with defaults):**
45
- ```typescript
46
- <RenownUserProvider>
47
- <App />
48
- </RenownUserProvider>
49
- ```
50
-
51
- **With custom configuration:**
52
- ```typescript
53
- <RenownUserProvider
54
- renownUrl={process.env.NEXT_PUBLIC_RENOWN_URL}
55
- networkId="eip155"
56
- chainId="1"
57
- loadingComponent={
58
- <div className="loading-screen">
59
- <Spinner />
60
- <p>Initializing...</p>
61
- </div>
62
- }
63
- errorComponent={(error, retry) => (
64
- <div className="error-screen">
65
- <h2>Failed to initialize</h2>
66
- <p>{error.message}</p>
67
- <button onClick={retry}>Try Again</button>
68
- </div>
69
- )}
70
- >
71
- <App />
72
- </RenownUserProvider>
73
- ```
74
-
75
- #### Behavior
76
-
77
- - **Automatically initializes** Renown SDK and ConnectCrypto on mount
78
- - Creates global `window.renown` and `window.connectCrypto` instances
79
- - Checks sessionStorage for existing sessions
80
- - Handles Renown authentication redirects
81
- - Shows `loadingComponent` during initialization (if provided)
82
- - Shows `errorComponent` if initialization fails (if provided)
83
- - If no custom components provided, renders children immediately
84
- - Provides auth context to all children
85
-
86
- ---
87
-
88
- ### `RenownAuthButton`
89
-
90
- Smart button component that adapts based on authentication state.
91
-
92
- #### Props
93
-
94
- ```typescript
95
- interface RenownAuthButtonProps {
96
- className?: string
97
- profileBaseUrl?: string
98
- renderAuthenticated?: (props: RenownAuthButtonRenderProps) => React.ReactNode
99
- renderUnauthenticated?: (props: { openRenown: () => void; isLoading: boolean }) => React.ReactNode
100
- renderLoading?: () => React.ReactNode
101
- showUsername?: boolean
102
- showLogoutButton?: boolean
103
- logoutButtonText?: string
104
- }
105
- ```
106
-
107
- | Prop | Type | Default | Description |
108
- |------|------|---------|-------------|
109
- | `className` | `string` | `""` | Custom CSS class |
110
- | `profileBaseUrl` | `string` | `"https://www.renown.id/profile"` | Base URL for profile |
111
- | `renderAuthenticated` | `function` | Default renderer | Custom authenticated state |
112
- | `renderUnauthenticated` | `function` | Default renderer | Custom unauthenticated state |
113
- | `renderLoading` | `function` | Default renderer | Custom loading state |
114
- | `showUsername` | `boolean` | `true` | Show username next to avatar |
115
- | `showLogoutButton` | `boolean` | `false` | Show logout button |
116
- | `logoutButtonText` | `string` | `"Logout"` | Logout button text |
117
-
118
- #### Example
119
-
120
- ```typescript
121
- import { RenownAuthButton } from '@renown/sdk'
122
-
123
- // Basic usage
124
- <RenownAuthButton showLogoutButton />
125
-
126
- // Custom rendering
127
- <RenownAuthButton
128
- renderAuthenticated={({ user, logout }) => (
129
- <div>
130
- <span>{user.name}</span>
131
- <button onClick={logout}>Sign Out</button>
132
- </div>
133
- )}
134
- renderUnauthenticated={({ openRenown }) => (
135
- <button onClick={openRenown}>Sign In</button>
136
- )}
137
- />
138
- ```
139
-
140
- ---
141
-
142
- ### `RenownLoginButton`
143
-
144
- A login button with Renown branding. By default, clicking the button triggers login directly. Optionally shows a popover with connect option.
145
-
146
- #### Props
147
-
148
- ```typescript
149
- interface RenownLoginButtonProps {
150
- onLogin: (() => void) | undefined
151
- darkMode?: boolean
152
- style?: CSSProperties
153
- className?: string
154
- renderTrigger?: (props: {
155
- onMouseEnter: () => void
156
- onMouseLeave: () => void
157
- isLoading: boolean
158
- }) => ReactNode
159
- showPopover?: boolean
160
- }
161
- ```
162
-
163
- | Prop | Type | Default | Description |
164
- |------|------|---------|-------------|
165
- | `onLogin` | `() => void \| undefined` | - | Callback when login is requested |
166
- | `darkMode` | `boolean` | `false` | Enable dark mode styling |
167
- | `style` | `CSSProperties` | - | Custom styles for the button |
168
- | `className` | `string` | - | Custom class name |
169
- | `renderTrigger` | `function` | - | Custom render function for the trigger button |
170
- | `showPopover` | `boolean` | `false` | Show a popover with connect option instead of triggering login directly |
171
-
172
- #### Example
173
-
174
- ```typescript
175
- import { RenownLoginButton } from '@renown/sdk'
176
-
177
- // Direct login (default) - clicks trigger onLogin immediately
178
- <RenownLoginButton onLogin={handleLogin} />
179
-
180
- // With popover - shows hover popover with "Connect" button
181
- <RenownLoginButton onLogin={handleLogin} showPopover />
182
-
183
- // Dark mode
184
- <RenownLoginButton onLogin={handleLogin} darkMode />
185
-
186
- // Custom trigger
187
- <RenownLoginButton
188
- onLogin={handleLogin}
189
- renderTrigger={({ onMouseEnter, onMouseLeave, isLoading }) => (
190
- <button onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
191
- {isLoading ? 'Loading...' : 'Sign In'}
192
- </button>
193
- )}
194
- />
195
- ```
196
-
197
- ---
198
-
199
- ## Hooks
200
-
201
- ### `useUser()`
202
-
203
- Access authentication state and methods.
204
-
205
- #### Returns
206
-
207
- ```typescript
208
- interface RenownUserContextValue {
209
- user: User | null
210
- loginStatus: LoginStatus
211
- isLoading: boolean
212
- isInitialized: boolean
213
- login: (userDid?: string) => Promise<void>
214
- logout: () => Promise<void>
215
- openRenown: () => void
216
- connectCrypto: IConnectCrypto | null
217
- renown: IRenown | null
218
- }
219
- ```
220
-
221
- | Property | Type | Description |
222
- |----------|------|-------------|
223
- | `user` | `User \| null` | Current authenticated user or null |
224
- | `loginStatus` | `LoginStatus` | Current authentication status |
225
- | `isLoading` | `boolean` | Whether an auth operation is in progress |
226
- | `isInitialized` | `boolean` | Whether the auth system has initialized |
227
- | `login` | `function` | Authenticate with optional DID |
228
- | `logout` | `function` | Log out current user |
229
- | `openRenown` | `function` | Open Renown authentication portal |
230
- | `connectCrypto` | `IConnectCrypto \| null` | ConnectCrypto instance for cryptographic operations |
231
- | `renown` | `IRenown \| null` | Renown SDK instance |
232
-
233
- #### Example
234
-
235
- ```typescript
236
- function MyComponent() {
237
- const {
238
- user,
239
- loginStatus,
240
- isLoading,
241
- login,
242
- logout,
243
- openRenown,
244
- connectCrypto,
245
- renown
246
- } = useUser()
247
-
248
- if (isLoading) return <div>Loading...</div>
249
- if (!user) return <button onClick={openRenown}>Login</button>
250
- return <button onClick={logout}>Logout</button>
251
- }
252
- ```
253
-
254
- #### Throws
255
-
256
- Throws an error if used outside of `<RenownUserProvider>`:
257
-
258
- ```
259
- Error: useUser must be used within a RenownUserProvider
260
- ```
261
-
262
- ---
263
-
264
- ## Functions
265
-
266
- ### `initRenown()`
267
-
268
- Initialize the Renown SDK.
269
-
270
- #### Signature
271
-
272
- ```typescript
273
- function initRenown(
274
- did: string,
275
- networkId: string,
276
- renownUrl: string
277
- ): Promise<IRenown>
278
- ```
279
-
280
- #### Parameters
281
-
282
- | Parameter | Type | Description |
283
- |-----------|------|-------------|
284
- | `did` | `string` | Decentralized identifier (DID) |
285
- | `networkId` | `string` | Network identifier (e.g., 'eip155') |
286
- | `renownUrl` | `string` | Renown service URL |
287
-
288
- #### Returns
289
-
290
- `Promise<IRenown>` - Initialized Renown instance
291
-
292
- #### Example
293
-
294
- ```typescript
295
- import { initRenown } from '@renown/sdk'
296
-
297
- const renown = await initRenown(
298
- 'did:pkh:eip155:1:0x123...',
299
- 'eip155',
300
- 'https://www.renown.id'
301
- )
302
- ```
303
-
304
- ---
305
-
306
- ### `login()`
307
-
308
- Authenticate a user with Renown.
309
-
310
- #### Signature
311
-
312
- ```typescript
313
- function login(
314
- userDid: string | undefined,
315
- renown: IRenown | undefined,
316
- connectCrypto: IConnectCrypto | undefined
317
- ): Promise<User | undefined>
318
- ```
319
-
320
- #### Parameters
321
-
322
- | Parameter | Type | Description |
323
- |-----------|------|-------------|
324
- | `userDid` | `string \| undefined` | User's DID to authenticate |
325
- | `renown` | `IRenown \| undefined` | Renown instance |
326
- | `connectCrypto` | `IConnectCrypto \| undefined` | ConnectCrypto instance |
327
-
328
- #### Returns
329
-
330
- `Promise<User | undefined>` - Authenticated user or undefined
331
-
332
- #### Side Effects
333
-
334
- - Stores user session in sessionStorage
335
- - Fetches user profile data
336
- - Updates auth state
337
-
338
- #### Example
339
-
340
- ```typescript
341
- import { login } from '@renown/sdk'
342
-
343
- const user = await login(
344
- 'did:pkh:eip155:1:0x123...',
345
- window.renown,
346
- window.connectCrypto
347
- )
348
- ```
349
-
350
- ---
351
-
352
- ### `logout()`
353
-
354
- Log out the current user.
355
-
356
- #### Signature
357
-
358
- ```typescript
359
- function logout(): Promise<void>
360
- ```
361
-
362
- #### Returns
363
-
364
- `Promise<void>`
365
-
366
- #### Side Effects
367
-
368
- - Clears sessionStorage
369
- - Calls renown.logout()
370
- - Removes JWT handler
371
-
372
- #### Example
373
-
374
- ```typescript
375
- import { logout } from '@renown/sdk'
376
-
377
- await logout()
378
- ```
379
-
380
- ---
381
-
382
- ### `openRenown()`
383
-
384
- Open the Renown authentication portal.
385
-
386
- #### Signature
387
-
388
- ```typescript
389
- function openRenown(): void
390
- ```
391
-
392
- #### Returns
393
-
394
- `void`
395
-
396
- #### Behavior
397
-
398
- - Constructs authentication URL with current DID
399
- - Adds network and chain parameters
400
- - Sets return URL to current location
401
- - Redirects to Renown portal
402
-
403
- #### Example
404
-
405
- ```typescript
406
- import { openRenown } from '@renown/sdk'
407
-
408
- function MyLoginButton() {
409
- return <button onClick={openRenown}>Login</button>
410
- }
411
-
412
- // Or use the built-in RenownAuthButton component
413
- import { RenownAuthButton } from '@renown/sdk'
414
-
415
- function Header() {
416
- return <RenownAuthButton />
417
- }
418
- ```
419
-
420
- ---
421
-
422
- ### `handleRenownReturn()`
423
-
424
- Process authentication redirect from Renown.
425
-
426
- #### Signature
427
-
428
- ```typescript
429
- function handleRenownReturn(): Promise<void>
430
- ```
431
-
432
- #### Returns
433
-
434
- `Promise<void>`
435
-
436
- #### Behavior
437
-
438
- - Checks URL for authentication parameters
439
- - Extracts user DID from query string
440
- - Calls login with the DID
441
- - Cleans up URL parameters
442
-
443
- #### Example
444
-
445
- ```typescript
446
- import { handleRenownReturn } from '@renown/sdk'
447
-
448
- // Called automatically by UserProvider
449
- useEffect(() => {
450
- handleRenownReturn()
451
- }, [])
452
- ```
453
-
454
- ---
455
-
456
- ### `fetchProfileDataForUser()`
457
-
458
- Fetch user profile data from Renown API.
459
-
460
- #### Signature
461
-
462
- ```typescript
463
- function fetchProfileDataForUser(user: User): Promise<User>
464
- ```
465
-
466
- #### Parameters
467
-
468
- | Parameter | Type | Description |
469
- |-----------|------|-------------|
470
- | `user` | `User` | User object to enrich with profile data |
471
-
472
- #### Returns
473
-
474
- `Promise<User>` - User with profile data
475
-
476
- #### Behavior
477
-
478
- - Extracts ETH address from user's DID
479
- - Calls Renown profile API
480
- - Enriches user object with profile data (name, avatar, etc.)
481
- - Returns original user if profile not found
482
-
483
- #### Example
484
-
485
- ```typescript
486
- import { fetchProfileDataForUser } from '@renown/sdk'
487
-
488
- const userWithProfile = await fetchProfileDataForUser(user)
489
- console.log(userWithProfile.name) // Display name
490
- console.log(userWithProfile.avatar) // Avatar URL
491
- ```
492
-
493
- ---
494
-
495
- ### `reauthenticateFromSession()`
496
-
497
- Restore authentication from stored session.
498
-
499
- #### Signature
500
-
501
- ```typescript
502
- function reauthenticateFromSession(): Promise<User | null>
503
- ```
504
-
505
- #### Returns
506
-
507
- `Promise<User | null>` - Restored user or null
508
-
509
- #### Behavior
510
-
511
- - Checks for stored session in sessionStorage
512
- - Calls login with stored DID
513
- - Fetches fresh profile data
514
- - Returns null if session invalid or expired
515
-
516
- #### Example
517
-
518
- ```typescript
519
- import { reauthenticateFromSession } from '@renown/sdk'
520
-
521
- const user = await reauthenticateFromSession()
522
- if (user) {
523
- console.log('Session restored for:', user.did)
524
- }
525
- ```
526
-
527
- ---
528
-
529
- ### `extractEthAddressFromDid()`
530
-
531
- Extract Ethereum address from a DID.
532
-
533
- #### Signature
534
-
535
- ```typescript
536
- function extractEthAddressFromDid(did: string): string | null
537
- ```
538
-
539
- #### Parameters
540
-
541
- | Parameter | Type | Description |
542
- |-----------|------|-------------|
543
- | `did` | `string` | DID string (e.g., 'did:pkh:eip155:1:0x123...') |
544
-
545
- #### Returns
546
-
547
- `string | null` - Ethereum address or null if invalid
548
-
549
- #### Example
550
-
551
- ```typescript
552
- import { extractEthAddressFromDid } from '@renown/sdk'
553
-
554
- const address = extractEthAddressFromDid('did:pkh:eip155:1:0x1234...')
555
- console.log(address) // '0x1234...'
556
- ```
557
-
558
- ---
559
-
560
- ## Types
561
-
562
- ### `User`
563
-
564
- Represents an authenticated user.
565
-
566
- ```typescript
567
- interface User {
568
- did: string // Decentralized identifier
569
- address: string // Ethereum address
570
- name?: string // Display name from profile
571
- email?: string // Email address
572
- avatar?: string // Avatar image URL
573
- ethAddress?: string // Ethereum address (duplicate of address)
574
- }
575
- ```
576
-
577
- ---
578
-
579
- ### `LoginStatus`
580
-
581
- Authentication status enumeration.
582
-
583
- ```typescript
584
- type LoginStatus =
585
- | 'initial' // Not yet checked
586
- | 'checking' // Currently checking auth
587
- | 'authorized' // User is authenticated
588
- | 'not-authorized' // User is not authenticated
589
- ```
590
-
591
- ---
592
-
593
- ### `RenownUserContextValue`
594
-
595
- Type for the authentication context value.
596
-
597
- ```typescript
598
- interface RenownUserContextValue {
599
- user: User | null
600
- loginStatus: LoginStatus
601
- isLoading: boolean
602
- isInitialized: boolean
603
- login: (userDid?: string) => Promise<void>
604
- logout: () => Promise<void>
605
- openRenown: () => void
606
- connectCrypto: IConnectCrypto | null
607
- renown: IRenown | null
608
- }
609
- ```
610
-
611
- ---
612
-
613
- ### `IRenown`
614
-
615
- Interface for the Renown instance.
616
-
617
- ```typescript
618
- interface IRenown {
619
- user: User | undefined | (() => Promise<User | undefined>)
620
- login: (did: string) => Promise<User | undefined>
621
- logout: () => Promise<void>
622
- on: (event: string, handler: Function) => Unsubscribe
623
- }
624
- ```
625
-
626
- ---
627
-
628
- ### `IConnectCrypto`
629
-
630
- Interface for the ConnectCrypto instance.
631
-
632
- ```typescript
633
- interface IConnectCrypto {
634
- did: () => Promise<string>
635
- // Additional methods...
636
- }
637
- ```
638
-
639
- ---
640
-
641
- ## Classes
642
-
643
- ### `ConnectCrypto`
644
-
645
- Manages cryptographic operations and DID generation.
646
-
647
- #### Constructor
648
-
649
- ```typescript
650
- constructor(keyStorage: IKeyStorage)
651
- ```
652
-
653
- #### Parameters
654
-
655
- | Parameter | Type | Description |
656
- |-----------|------|-------------|
657
- | `keyStorage` | `IKeyStorage` | Key storage implementation |
658
-
659
- #### Methods
660
-
661
- ##### `did()`
662
-
663
- Get the DID for the current key.
664
-
665
- ```typescript
666
- async did(): Promise<string>
667
- ```
668
-
669
- **Returns:** `Promise<string>` - The DID
670
-
671
- **Example:**
672
- ```typescript
673
- const connectCrypto = new ConnectCrypto(new BrowserKeyStorage())
674
- const did = await connectCrypto.did()
675
- console.log(did) // 'did:pkh:eip155:1:0x...'
676
- ```
677
-
678
- ---
679
-
680
- ### `BrowserKeyStorage`
681
-
682
- Browser-based key storage using IndexedDB.
683
-
684
- #### Constructor
685
-
686
- ```typescript
687
- constructor()
688
- ```
689
-
690
- #### Usage
691
-
692
- ```typescript
693
- import { BrowserKeyStorage, ConnectCrypto } from '@renown/sdk'
694
-
695
- const keyStorage = new BrowserKeyStorage()
696
- const connectCrypto = new ConnectCrypto(keyStorage)
697
- ```
698
-
699
- ---
700
-
701
- ### `SessionStorageManager`
702
-
703
- Manages user session persistence.
704
-
705
- #### Static Methods
706
-
707
- ##### `setUserData()`
708
-
709
- Store user session data.
710
-
711
- ```typescript
712
- static setUserData(data: {
713
- user: User
714
- userDid: string
715
- loginStatus: LoginStatus
716
- timestamp: number
717
- }): void
718
- ```
719
-
720
- **Example:**
721
- ```typescript
722
- SessionStorageManager.setUserData({
723
- user: currentUser,
724
- userDid: currentUser.did,
725
- loginStatus: 'authorized',
726
- timestamp: Date.now()
727
- })
728
- ```
729
-
730
- ##### `getUserData()`
731
-
732
- Retrieve stored user session.
733
-
734
- ```typescript
735
- static getUserData(): {
736
- user: User
737
- userDid: string
738
- loginStatus: LoginStatus
739
- timestamp: number
740
- } | null
741
- ```
742
-
743
- **Returns:** Session data or null
744
-
745
- **Example:**
746
- ```typescript
747
- const session = SessionStorageManager.getUserData()
748
- if (session) {
749
- console.log('Found session for:', session.user.did)
750
- }
751
- ```
752
-
753
- ##### `clearUserData()`
754
-
755
- Clear stored session.
756
-
757
- ```typescript
758
- static clearUserData(): void
759
- ```
760
-
761
- **Example:**
762
- ```typescript
763
- SessionStorageManager.clearUserData()
764
- ```
765
-
766
- ##### `isUserDataValid()`
767
-
768
- Check if session data is valid.
769
-
770
- ```typescript
771
- static isUserDataValid(data: {
772
- user: User
773
- userDid: string
774
- loginStatus: LoginStatus
775
- timestamp: number
776
- }): boolean
777
- ```
778
-
779
- **Returns:** `boolean` - Whether session is valid
780
-
781
- **Example:**
782
- ```typescript
783
- const data = SessionStorageManager.getUserData()
784
- if (data && SessionStorageManager.isUserDataValid(data)) {
785
- // Session is valid
786
- }
787
- ```
788
-
789
- ##### `getStoredUserDid()`
790
-
791
- Get stored user DID.
792
-
793
- ```typescript
794
- static getStoredUserDid(): string | null
795
- ```
796
-
797
- **Returns:** `string | null` - Stored DID or null
798
-
799
- ---
800
-
801
- ## Constants
802
-
803
- ### `RENOWN_URL`
804
-
805
- Default Renown service URL.
806
-
807
- ```typescript
808
- const RENOWN_URL: string = 'https://www.renown.id'
809
- ```
810
-
811
- ---
812
-
813
- ### `RENOWN_NETWORK_ID`
814
-
815
- Default network identifier.
816
-
817
- ```typescript
818
- const RENOWN_NETWORK_ID: string = 'eip155'
819
- ```
820
-
821
- ---
822
-
823
- ### `RENOWN_CHAIN_ID`
824
-
825
- Default chain identifier.
826
-
827
- ```typescript
828
- const RENOWN_CHAIN_ID: string = '1'
829
- ```
830
-
831
- ---
832
-
833
- ## Global Window Extensions
834
-
835
- The SDK extends the global `Window` interface:
836
-
837
- ```typescript
838
- declare global {
839
- interface Window {
840
- renown?: IRenown
841
- connectCrypto?: IConnectCrypto
842
- reactor?: {
843
- setGenerateJwtHandler: (handler: (driveUrl: string) => Promise<string>) => void
844
- removeJwtHandler: () => void
845
- }
846
- }
847
- }
848
- ```
849
-
850
- ### `window.renown`
851
-
852
- Global Renown instance after initialization.
853
-
854
- **Usage:**
855
- ```typescript
856
- if (window.renown) {
857
- const user = await window.renown.login('did:pkh:...')
858
- }
859
- ```
860
-
861
- ### `window.connectCrypto`
862
-
863
- Global ConnectCrypto instance after initialization.
864
-
865
- **Usage:**
866
- ```typescript
867
- if (window.connectCrypto) {
868
- const did = await window.connectCrypto.did()
869
- }
870
- ```
871
-
872
- ---
873
-
874
- ## Error Handling
875
-
876
- ### Common Errors
877
-
878
- #### `useUser must be used within a RenownUserProvider`
879
-
880
- **Cause:** Using `useUser()` outside of `<RenownUserProvider>`
881
-
882
- **Solution:** Wrap your component tree with `<RenownUserProvider>`
883
-
884
- ```typescript
885
- <RenownUserProvider>
886
- <YourComponent /> {/* ✅ Can use useUser */}
887
- </RenownUserProvider>
888
- ```
889
-
890
- #### `Invalid DID format`
891
-
892
- **Cause:** DID doesn't match expected format `did:pkh:networkId:chainId:address`
893
-
894
- **Solution:** Ensure DID is properly formatted
895
-
896
- ```typescript
897
- // ✅ Valid
898
- 'did:pkh:eip155:1:0x1234567890123456789012345678901234567890'
899
-
900
- // ❌ Invalid
901
- 'did:1234567890123456789012345678901234567890'
902
- ```
903
-
904
- #### `Renown or ConnectCrypto not available`
905
-
906
- **Cause:** SDK initialization failed
907
-
908
- **Solution:** The RenownUserProvider automatically initializes the SDK. If you see this error:
909
-
910
- 1. Check that `<RenownUserProvider>` is mounted
911
- 2. Check browser console for initialization errors
912
- 3. Verify network connectivity to Renown service
913
- 4. Try providing an `errorComponent` prop to see detailed error messages
914
-
915
- ```typescript
916
- <RenownUserProvider
917
- errorComponent={(error, retry) => (
918
- <div>
919
- <p>Init failed: {error.message}</p>
920
- <button onClick={retry}>Retry</button>
921
- </div>
922
- )}
923
- >
924
- <App />
925
- </RenownUserProvider>
926
- ```
927
-
928
- ---
929
-
930
- ## TypeScript Support
931
-
932
- The SDK is fully typed. Import types as needed:
933
-
934
- ```typescript
935
- import type {
936
- User,
937
- LoginStatus,
938
- RenownUserContextValue,
939
- IRenown,
940
- IConnectCrypto,
941
- } from '@renown/sdk'
942
- ```
943
-
944
- ---
945
-
946
- ## Version Compatibility
947
-
948
- | SDK Version | React Version | TypeScript Version |
949
- |-------------|---------------|-------------------|
950
- | 5.x | 18.x - 19.x | 4.5+ |
951
- | 4.x | 18.x | 4.5+ |
952
-
953
- ---
954
-
955
- ## Related Documentation
956
-
957
- - [Authentication Guide](./01-Authentication.md) - Comprehensive auth implementation guide