@renown/sdk 6.0.0-dev.9 → 6.0.0-dev.90
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/README.md +47 -438
- package/dist/src/common.d.ts +16 -8
- package/dist/src/common.d.ts.map +1 -1
- package/dist/src/common.js +78 -38
- package/dist/src/common.js.map +1 -1
- package/dist/src/crypto/browser-key-storage.d.ts +4 -2
- package/dist/src/crypto/browser-key-storage.d.ts.map +1 -1
- package/dist/src/crypto/browser-key-storage.js +54 -51
- package/dist/src/crypto/browser-key-storage.js.map +1 -1
- package/dist/src/crypto/common.d.ts +6 -0
- package/dist/src/crypto/common.d.ts.map +1 -0
- package/dist/src/crypto/common.js +8 -0
- package/dist/src/crypto/common.js.map +1 -0
- package/dist/src/crypto/index.d.ts +1 -34
- package/dist/src/crypto/index.d.ts.map +1 -1
- package/dist/src/crypto/index.js +1 -128
- package/dist/src/crypto/index.js.map +1 -1
- package/dist/src/crypto/memory-key-storage.d.ts +9 -0
- package/dist/src/crypto/memory-key-storage.d.ts.map +1 -0
- package/dist/src/crypto/memory-key-storage.js +18 -0
- package/dist/src/crypto/memory-key-storage.js.map +1 -0
- package/dist/src/crypto/node-key-storage.d.ts +16 -3
- package/dist/src/crypto/node-key-storage.d.ts.map +1 -1
- package/dist/src/crypto/node-key-storage.js +82 -42
- package/dist/src/crypto/node-key-storage.js.map +1 -1
- package/dist/src/crypto/node.d.ts +1 -0
- package/dist/src/crypto/node.d.ts.map +1 -1
- package/dist/src/crypto/node.js +1 -1
- package/dist/src/crypto/node.js.map +1 -1
- package/dist/src/crypto/renown-crypto-builder.d.ts +11 -0
- package/dist/src/crypto/renown-crypto-builder.d.ts.map +1 -0
- package/dist/src/crypto/renown-crypto-builder.js +34 -0
- package/dist/src/crypto/renown-crypto-builder.js.map +1 -0
- package/dist/src/crypto/renown-crypto.d.ts +26 -0
- package/dist/src/crypto/renown-crypto.d.ts.map +1 -0
- package/dist/src/crypto/renown-crypto.js +56 -0
- package/dist/src/crypto/renown-crypto.js.map +1 -0
- package/dist/src/crypto/signer.d.ts +61 -8
- package/dist/src/crypto/signer.d.ts.map +1 -1
- package/dist/src/crypto/signer.js +98 -28
- package/dist/src/crypto/signer.js.map +1 -1
- package/dist/src/crypto/types.d.ts +27 -0
- package/dist/src/crypto/types.d.ts.map +1 -0
- package/dist/src/crypto/types.js +2 -0
- package/dist/src/crypto/types.js.map +1 -0
- package/dist/src/crypto/utils.d.ts +13 -0
- package/dist/src/crypto/utils.d.ts.map +1 -0
- package/dist/src/crypto/utils.js +39 -0
- package/dist/src/crypto/utils.js.map +1 -0
- package/dist/src/event/event.browser.d.ts.map +1 -1
- package/dist/src/event/event.node.d.ts.map +1 -1
- package/dist/src/event/memory.d.ts +8 -0
- package/dist/src/event/memory.d.ts.map +1 -0
- package/dist/src/event/memory.js +16 -0
- package/dist/src/event/memory.js.map +1 -0
- package/dist/src/index.d.ts +4 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/init.browser.d.ts +51 -2
- package/dist/src/init.browser.d.ts.map +1 -1
- package/dist/src/init.browser.js +62 -3
- package/dist/src/init.browser.js.map +1 -1
- package/dist/src/init.node.d.ts +28 -2
- package/dist/src/init.node.d.ts.map +1 -1
- package/dist/src/init.node.js +26 -4
- package/dist/src/init.node.js.map +1 -1
- package/dist/src/node.d.ts +7 -3
- package/dist/src/node.d.ts.map +1 -1
- package/dist/src/node.js +7 -3
- package/dist/src/node.js.map +1 -1
- package/dist/src/profile.d.ts +3 -0
- package/dist/src/profile.d.ts.map +1 -0
- package/dist/src/profile.js +22 -0
- package/dist/src/profile.js.map +1 -0
- package/dist/src/renown-builder.d.ts +68 -0
- package/dist/src/renown-builder.d.ts.map +1 -0
- package/dist/src/renown-builder.js +130 -0
- package/dist/src/renown-builder.js.map +1 -0
- package/dist/src/storage/common.d.ts +14 -10
- package/dist/src/storage/common.d.ts.map +1 -1
- package/dist/src/storage/common.js +16 -3
- package/dist/src/storage/common.js.map +1 -1
- package/dist/src/storage/storage.browser.d.ts +1 -0
- package/dist/src/storage/storage.browser.d.ts.map +1 -1
- package/dist/src/storage/storage.browser.js +3 -1
- package/dist/src/storage/storage.browser.js.map +1 -1
- package/dist/src/storage/storage.node.d.ts +1 -1
- package/dist/src/storage/storage.node.d.ts.map +1 -1
- package/dist/src/storage/storage.node.js +7 -5
- package/dist/src/storage/storage.node.js.map +1 -1
- package/dist/src/types.d.ts +51 -5
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +17 -10
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +14 -0
- package/dist/src/utils.js.map +1 -1
- package/dist/{tests → test}/auth.test.d.ts.map +1 -1
- package/dist/test/auth.test.js.map +1 -0
- package/dist/test/crypto/signer.test.d.ts +2 -0
- package/dist/test/crypto/signer.test.d.ts.map +1 -0
- package/dist/test/crypto/signer.test.js +184 -0
- package/dist/test/crypto/signer.test.js.map +1 -0
- package/dist/test/renown.test.d.ts +2 -0
- package/dist/test/renown.test.d.ts.map +1 -0
- package/dist/test/renown.test.js +287 -0
- package/dist/test/renown.test.js.map +1 -0
- package/dist/test/storage.node.test.d.ts +2 -0
- package/dist/test/storage.node.test.d.ts.map +1 -0
- package/dist/test/storage.node.test.js +66 -0
- package/dist/test/storage.node.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/{e2e/fixtures/vite.config.d.ts → vitest.config.d.ts} +1 -1
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +7 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +4 -28
- package/dist/e2e/fixtures/main.d.ts +0 -2
- package/dist/e2e/fixtures/main.d.ts.map +0 -1
- package/dist/e2e/fixtures/main.js +0 -97
- package/dist/e2e/fixtures/main.js.map +0 -1
- package/dist/e2e/fixtures/vite.config.d.ts.map +0 -1
- package/dist/e2e/fixtures/vite.config.js +0 -10
- package/dist/e2e/fixtures/vite.config.js.map +0 -1
- package/dist/e2e/renown-components.spec.d.ts +0 -2
- package/dist/e2e/renown-components.spec.d.ts.map +0 -1
- package/dist/e2e/renown-components.spec.js +0 -155
- package/dist/e2e/renown-components.spec.js.map +0 -1
- package/dist/playwright.config.d.ts +0 -3
- package/dist/playwright.config.d.ts.map +0 -1
- package/dist/playwright.config.js +0 -25
- package/dist/playwright.config.js.map +0 -1
- package/dist/src/assets/assets.d.ts +0 -19
- package/dist/src/assets/renown-hover.svg +0 -17
- package/dist/src/assets/renown-light.svg +0 -15
- package/dist/src/assets/renown-short-hover.png +0 -0
- package/dist/src/assets/renown-short.png +0 -0
- package/dist/src/assets/renown.svg +0 -16
- package/dist/src/components/RenownAuthButton.d.ts +0 -62
- package/dist/src/components/RenownAuthButton.d.ts.map +0 -1
- package/dist/src/components/RenownAuthButton.js +0 -82
- package/dist/src/components/RenownAuthButton.js.map +0 -1
- package/dist/src/components/RenownLoginButton.d.ts +0 -48
- package/dist/src/components/RenownLoginButton.d.ts.map +0 -1
- package/dist/src/components/RenownLoginButton.js +0 -175
- package/dist/src/components/RenownLoginButton.js.map +0 -1
- package/dist/src/components/RenownUserButton.d.ts +0 -66
- package/dist/src/components/RenownUserButton.d.ts.map +0 -1
- package/dist/src/components/RenownUserButton.js +0 -216
- package/dist/src/components/RenownUserButton.js.map +0 -1
- package/dist/src/components/icons.d.ts +0 -25
- package/dist/src/components/icons.d.ts.map +0 -1
- package/dist/src/components/icons.js +0 -24
- package/dist/src/components/icons.js.map +0 -1
- package/dist/src/components/image-data.d.ts +0 -3
- package/dist/src/components/image-data.d.ts.map +0 -1
- package/dist/src/components/image-data.js +0 -4
- package/dist/src/components/image-data.js.map +0 -1
- package/dist/src/components/index.d.ts +0 -8
- package/dist/src/components/index.d.ts.map +0 -1
- package/dist/src/components/index.js +0 -5
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/hooks/index.d.ts +0 -2
- package/dist/src/hooks/index.d.ts.map +0 -1
- package/dist/src/hooks/index.js +0 -2
- package/dist/src/hooks/index.js.map +0 -1
- package/dist/src/hooks/use-user.d.ts +0 -21
- package/dist/src/hooks/use-user.d.ts.map +0 -1
- package/dist/src/hooks/use-user.js +0 -30
- package/dist/src/hooks/use-user.js.map +0 -1
- package/dist/src/index.browser.d.ts +0 -4
- package/dist/src/index.browser.d.ts.map +0 -1
- package/dist/src/index.browser.js +0 -4
- package/dist/src/index.browser.js.map +0 -1
- package/dist/src/index.node.d.ts +0 -4
- package/dist/src/index.node.d.ts.map +0 -1
- package/dist/src/index.node.js +0 -4
- package/dist/src/index.node.js.map +0 -1
- package/dist/src/lib/crypto/browser.d.ts +0 -8
- package/dist/src/lib/crypto/browser.d.ts.map +0 -1
- package/dist/src/lib/crypto/browser.js +0 -73
- package/dist/src/lib/crypto/browser.js.map +0 -1
- package/dist/src/lib/crypto/index.d.ts +0 -36
- package/dist/src/lib/crypto/index.d.ts.map +0 -1
- package/dist/src/lib/crypto/index.js +0 -150
- package/dist/src/lib/crypto/index.js.map +0 -1
- package/dist/src/lib/crypto/node.d.ts +0 -8
- package/dist/src/lib/crypto/node.d.ts.map +0 -1
- package/dist/src/lib/crypto/node.js +0 -67
- package/dist/src/lib/crypto/node.js.map +0 -1
- package/dist/src/lib/renown/constants.d.ts +0 -130
- package/dist/src/lib/renown/constants.d.ts.map +0 -1
- package/dist/src/lib/renown/constants.js +0 -40
- package/dist/src/lib/renown/constants.js.map +0 -1
- package/dist/src/lib/renown/did-parser.d.ts +0 -28
- package/dist/src/lib/renown/did-parser.d.ts.map +0 -1
- package/dist/src/lib/renown/did-parser.js +0 -57
- package/dist/src/lib/renown/did-parser.js.map +0 -1
- package/dist/src/lib/renown/index.d.ts +0 -4
- package/dist/src/lib/renown/index.d.ts.map +0 -1
- package/dist/src/lib/renown/index.js +0 -4
- package/dist/src/lib/renown/index.js.map +0 -1
- package/dist/src/lib/renown/utils.d.ts +0 -33
- package/dist/src/lib/renown/utils.d.ts.map +0 -1
- package/dist/src/lib/renown/utils.js +0 -207
- package/dist/src/lib/renown/utils.js.map +0 -1
- package/dist/src/lib/session-storage.d.ts +0 -40
- package/dist/src/lib/session-storage.d.ts.map +0 -1
- package/dist/src/lib/session-storage.js +0 -107
- package/dist/src/lib/session-storage.js.map +0 -1
- package/dist/src/providers/index.d.ts +0 -3
- package/dist/src/providers/index.d.ts.map +0 -1
- package/dist/src/providers/index.js +0 -2
- package/dist/src/providers/index.js.map +0 -1
- package/dist/src/providers/renown-user-provider.d.ts +0 -72
- package/dist/src/providers/renown-user-provider.d.ts.map +0 -1
- package/dist/src/providers/renown-user-provider.js +0 -171
- package/dist/src/providers/renown-user-provider.js.map +0 -1
- package/dist/tests/auth.test.js.map +0 -1
- /package/dist/{tests → test}/auth.test.d.ts +0 -0
- /package/dist/{tests → test}/auth.test.js +0 -0
package/README.md
CHANGED
|
@@ -1,489 +1,98 @@
|
|
|
1
1
|
# Renown SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core authentication SDK for Renown — handles credential verification, session management, and cryptographic operations.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- 🔐 **Authentication** - Complete authentication flow with session management
|
|
8
|
-
- 👤 **User Profiles** - Fetch and manage user profile data
|
|
9
|
-
- ⚛️ **React Integration** - Provider and hooks for seamless React integration
|
|
10
|
-
- 🎨 **UI Components** - Ready-to-use login and auth components
|
|
11
|
-
- 🔄 **Session Persistence** - Automatic session restoration across page reloads
|
|
12
|
-
- 🌐 **Renown Portal** - Easy integration with Renown authentication portal
|
|
13
|
-
- 📦 **Type-Safe** - Full TypeScript support
|
|
5
|
+
For React components and hooks, see [COMPONENTS.md](./COMPONENTS.md).
|
|
14
6
|
|
|
15
7
|
## Installation
|
|
16
8
|
|
|
17
9
|
```bash
|
|
18
10
|
npm install @renown/sdk
|
|
19
|
-
# or
|
|
20
|
-
yarn add @renown/sdk
|
|
21
|
-
# or
|
|
22
|
-
pnpm add @renown/sdk
|
|
23
11
|
```
|
|
24
12
|
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
### 1. Wrap Your App with RenownUserProvider
|
|
28
|
-
|
|
29
|
-
The SDK automatically initializes - just wrap your app!
|
|
13
|
+
## RenownBuilder
|
|
30
14
|
|
|
31
15
|
```typescript
|
|
32
|
-
|
|
33
|
-
import { RenownUserProvider } from '@renown/sdk'
|
|
16
|
+
import { RenownBuilder } from "@renown/sdk";
|
|
34
17
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<body>
|
|
39
|
-
<RenownUserProvider>
|
|
40
|
-
{children}
|
|
41
|
-
</RenownUserProvider>
|
|
42
|
-
</body>
|
|
43
|
-
</html>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
18
|
+
const renown = await new RenownBuilder("my-app")
|
|
19
|
+
.withBaseUrl("https://www.renown.id")
|
|
20
|
+
.build();
|
|
46
21
|
```
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export function Header() {
|
|
56
|
-
return (
|
|
57
|
-
<header>
|
|
58
|
-
<h1>My App</h1>
|
|
59
|
-
<RenownAuthButton showLogoutButton />
|
|
60
|
-
</header>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
```
|
|
23
|
+
**Builder methods:**
|
|
24
|
+
- `withBaseUrl(url)` — Renown server URL (default: `https://www.renown.id`)
|
|
25
|
+
- `withStorage(storage)` — Custom user data persistence (default: in-memory)
|
|
26
|
+
- `withEventEmitter(emitter)` — Custom event emitter for state changes
|
|
27
|
+
- `withCrypto(crypto)` — Pre-built crypto instance
|
|
28
|
+
- `withKeyPairStorage(storage)` — Key pair storage (crypto is built from this)
|
|
29
|
+
- `withProfileFetcher(fetcher)` — Custom profile enrichment strategy
|
|
64
30
|
|
|
65
|
-
|
|
31
|
+
## Renown Instance
|
|
66
32
|
|
|
67
33
|
```typescript
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
export function CustomAuth() {
|
|
71
|
-
const { user, openRenown, logout } = useUser()
|
|
72
|
-
|
|
73
|
-
if (!user) return <button onClick={openRenown}>Login</button>
|
|
74
|
-
return <button onClick={logout}>Logout</button>
|
|
75
|
-
}
|
|
76
|
-
```
|
|
34
|
+
// Login with a DID
|
|
35
|
+
const user = await renown.login("did:pkh:eip155:1:0x...");
|
|
77
36
|
|
|
78
|
-
|
|
37
|
+
// Check current state
|
|
38
|
+
renown.user; // User | undefined
|
|
39
|
+
renown.status; // "initial" | "checking" | "authorized" | "not-authorized"
|
|
79
40
|
|
|
80
|
-
|
|
41
|
+
// Listen to state changes
|
|
42
|
+
const unsub = renown.on("user", (user) => { ... });
|
|
43
|
+
const unsub2 = renown.on("status", (status) => { ... });
|
|
81
44
|
|
|
82
|
-
|
|
45
|
+
// Logout
|
|
46
|
+
await renown.logout();
|
|
83
47
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
import { RenownAuthButton } from '@renown/sdk'
|
|
88
|
-
|
|
89
|
-
<RenownAuthButton showLogoutButton />
|
|
48
|
+
// Bearer tokens for API auth
|
|
49
|
+
const token = await renown.getBearerToken({ expiresIn: 3600 });
|
|
50
|
+
const verified = await renown.verifyBearerToken(token);
|
|
90
51
|
```
|
|
91
52
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
## API Reference
|
|
95
|
-
|
|
96
|
-
### Components
|
|
97
|
-
|
|
98
|
-
#### `<RenownUserProvider>`
|
|
99
|
-
|
|
100
|
-
Central authentication provider that automatically initializes the SDK.
|
|
101
|
-
|
|
102
|
-
**Props:**
|
|
103
|
-
- `children`: React.ReactNode - **Required.** Your application components
|
|
104
|
-
- `renownUrl?`: string - Renown service URL (default: 'https://www.renown.id')
|
|
105
|
-
- `networkId?`: string - Network ID (default: 'eip155')
|
|
106
|
-
- `chainId?`: string - Chain ID (default: '1')
|
|
107
|
-
- `loadingComponent?`: React.ReactNode - Custom loading UI
|
|
108
|
-
- `errorComponent?`: (error, retry) => React.ReactNode - Custom error UI
|
|
109
|
-
|
|
110
|
-
**Example:**
|
|
111
|
-
```typescript
|
|
112
|
-
<RenownUserProvider>
|
|
113
|
-
<App />
|
|
114
|
-
</RenownUserProvider>
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**Custom Configuration:**
|
|
118
|
-
```typescript
|
|
119
|
-
<RenownUserProvider
|
|
120
|
-
renownUrl={process.env.NEXT_PUBLIC_RENOWN_URL}
|
|
121
|
-
loadingComponent={<Spinner />}
|
|
122
|
-
errorComponent={(error, retry) => <ErrorScreen error={error} onRetry={retry} />}
|
|
123
|
-
>
|
|
124
|
-
<App />
|
|
125
|
-
</RenownUserProvider>
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### Hooks
|
|
129
|
-
|
|
130
|
-
#### `useUser()`
|
|
131
|
-
|
|
132
|
-
Access authentication state and methods throughout your application.
|
|
133
|
-
|
|
134
|
-
**Returns:**
|
|
135
|
-
```typescript
|
|
136
|
-
{
|
|
137
|
-
user: User | null // Current authenticated user
|
|
138
|
-
loginStatus: LoginStatus // 'initial' | 'checking' | 'authorized' | 'not-authorized'
|
|
139
|
-
isLoading: boolean // Loading state for auth operations
|
|
140
|
-
isInitialized: boolean // Whether auth system is initialized
|
|
141
|
-
login: (userDid?: string) => Promise<void> // Login with optional DID
|
|
142
|
-
logout: () => Promise<void> // Logout current user
|
|
143
|
-
openRenown: () => void // Open Renown portal
|
|
144
|
-
}
|
|
145
|
-
```
|
|
53
|
+
## Types
|
|
146
54
|
|
|
147
|
-
**Example:**
|
|
148
55
|
```typescript
|
|
149
|
-
|
|
150
|
-
const { user, loginStatus, openRenown, logout } = useUser()
|
|
56
|
+
import type { User, LoginStatus, IRenown } from "@renown/sdk";
|
|
151
57
|
|
|
152
|
-
switch (loginStatus) {
|
|
153
|
-
case 'authorized':
|
|
154
|
-
return (
|
|
155
|
-
<div>
|
|
156
|
-
<h1>{user?.name || 'User'}</h1>
|
|
157
|
-
<p>{user?.did}</p>
|
|
158
|
-
{user?.avatar && <img src={user.avatar} alt="Avatar" />}
|
|
159
|
-
<button onClick={logout}>Logout</button>
|
|
160
|
-
</div>
|
|
161
|
-
)
|
|
162
|
-
case 'not-authorized':
|
|
163
|
-
return <button onClick={openRenown}>Login</button>
|
|
164
|
-
default:
|
|
165
|
-
return <div>Checking auth...</div>
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Types
|
|
171
|
-
|
|
172
|
-
#### `User`
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
58
|
interface User {
|
|
176
|
-
did: string
|
|
177
|
-
address: string
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
#### `LoginStatus`
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
type LoginStatus =
|
|
189
|
-
| 'initial' // Not yet checked
|
|
190
|
-
| 'checking' // Currently checking auth
|
|
191
|
-
| 'authorized' // User is authenticated
|
|
192
|
-
| 'not-authorized' // User is not authenticated
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Utility Functions
|
|
196
|
-
|
|
197
|
-
#### `fetchProfileDataForUser(user: User): Promise<User>`
|
|
198
|
-
|
|
199
|
-
Fetches additional profile data from the Renown API for a given user.
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
import { fetchProfileDataForUser } from '@renown/sdk'
|
|
203
|
-
|
|
204
|
-
const userWithProfile = await fetchProfileDataForUser(user)
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
#### `login(userDid: string, renown: IRenown, connectCrypto: IConnectCrypto)`
|
|
208
|
-
|
|
209
|
-
Performs login and stores session data.
|
|
210
|
-
|
|
211
|
-
#### `logout()`
|
|
212
|
-
|
|
213
|
-
Logs out the current user and clears session data.
|
|
214
|
-
|
|
215
|
-
#### `openRenown()`
|
|
216
|
-
|
|
217
|
-
Opens the Renown authentication portal.
|
|
218
|
-
|
|
219
|
-
#### `handleRenownReturn()`
|
|
220
|
-
|
|
221
|
-
Handles return from Renown authentication flow.
|
|
222
|
-
|
|
223
|
-
### Session Management
|
|
224
|
-
|
|
225
|
-
#### `SessionStorageManager`
|
|
226
|
-
|
|
227
|
-
Manages user session persistence in sessionStorage.
|
|
228
|
-
|
|
229
|
-
**Methods:**
|
|
230
|
-
- `setUserData(data)` - Store user data
|
|
231
|
-
- `getUserData()` - Retrieve stored user data
|
|
232
|
-
- `clearUserData()` - Clear session data
|
|
233
|
-
- `isUserDataValid(data)` - Check if session data is valid
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
import { SessionStorageManager } from '@renown/sdk'
|
|
237
|
-
|
|
238
|
-
// Store user session
|
|
239
|
-
SessionStorageManager.setUserData({
|
|
240
|
-
user: currentUser,
|
|
241
|
-
userDid: currentUser.did,
|
|
242
|
-
loginStatus: 'authorized',
|
|
243
|
-
timestamp: Date.now()
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
// Check session
|
|
247
|
-
const storedData = SessionStorageManager.getUserData()
|
|
248
|
-
if (storedData && SessionStorageManager.isUserDataValid(storedData)) {
|
|
249
|
-
// Session is valid
|
|
59
|
+
did: string;
|
|
60
|
+
address: `0x${string}`;
|
|
61
|
+
chainId: number;
|
|
62
|
+
networkId: string;
|
|
63
|
+
credential: PowerhouseVerifiableCredential | undefined;
|
|
64
|
+
profile?: RenownProfile;
|
|
65
|
+
ens?: { name?: string; avatarUrl?: string };
|
|
250
66
|
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
## Advanced Usage
|
|
254
|
-
|
|
255
|
-
### Custom Authentication Flow
|
|
256
|
-
|
|
257
|
-
You can implement custom authentication flows by directly using the SDK functions:
|
|
258
|
-
|
|
259
|
-
```typescript
|
|
260
|
-
import { login, logout, initRenown, ConnectCrypto, BrowserKeyStorage } from '@renown/sdk'
|
|
261
|
-
|
|
262
|
-
async function customLogin() {
|
|
263
|
-
// Initialize
|
|
264
|
-
const connectCrypto = new ConnectCrypto(new BrowserKeyStorage())
|
|
265
|
-
const renown = await initRenown(
|
|
266
|
-
await connectCrypto.did(),
|
|
267
|
-
'eip155',
|
|
268
|
-
'https://www.renown.id'
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
// Login
|
|
272
|
-
const userDid = await connectCrypto.did()
|
|
273
|
-
const user = await login(userDid, renown, connectCrypto)
|
|
274
|
-
|
|
275
|
-
return user
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
### Conditional Rendering Based on Auth
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
function ProtectedContent() {
|
|
283
|
-
const { user, loginStatus, openRenown } = useUser()
|
|
284
|
-
|
|
285
|
-
if (loginStatus !== 'authorized') {
|
|
286
|
-
return (
|
|
287
|
-
<div>
|
|
288
|
-
<h1>Please login to continue</h1>
|
|
289
|
-
<button onClick={openRenown}>Login</button>
|
|
290
|
-
</div>
|
|
291
|
-
)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return <div>Protected content for {user?.name}</div>
|
|
295
|
-
}
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### Handling Authentication Events
|
|
299
|
-
|
|
300
|
-
```typescript
|
|
301
|
-
function AuthListener() {
|
|
302
|
-
const { user, loginStatus } = useUser()
|
|
303
|
-
|
|
304
|
-
useEffect(() => {
|
|
305
|
-
if (loginStatus === 'authorized' && user) {
|
|
306
|
-
console.log('User logged in:', user)
|
|
307
|
-
// Analytics, notifications, etc.
|
|
308
|
-
}
|
|
309
|
-
}, [loginStatus, user])
|
|
310
|
-
|
|
311
|
-
return null
|
|
312
|
-
}
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
## Configuration
|
|
316
|
-
|
|
317
|
-
### RenownUserProvider Configuration
|
|
318
|
-
|
|
319
|
-
The RenownUserProvider accepts optional configuration props:
|
|
320
|
-
|
|
321
|
-
```typescript
|
|
322
|
-
<RenownUserProvider
|
|
323
|
-
renownUrl="https://www.renown.id" // Custom Renown URL
|
|
324
|
-
networkId="eip155" // Network ID (default)
|
|
325
|
-
chainId="1" // Chain ID (default)
|
|
326
|
-
>
|
|
327
|
-
<App />
|
|
328
|
-
</RenownUserProvider>
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
### Environment Variables
|
|
332
|
-
|
|
333
|
-
Use environment variables for dynamic configuration:
|
|
334
|
-
|
|
335
|
-
```typescript
|
|
336
|
-
<RenownUserProvider
|
|
337
|
-
renownUrl={process.env.NEXT_PUBLIC_RENOWN_URL || 'https://www.renown.id'}
|
|
338
|
-
>
|
|
339
|
-
<App />
|
|
340
|
-
</RenownUserProvider>
|
|
341
|
-
```
|
|
342
67
|
|
|
343
|
-
|
|
344
|
-
# .env
|
|
345
|
-
NEXT_PUBLIC_RENOWN_URL=https://www.renown.id
|
|
68
|
+
type LoginStatus = "initial" | "checking" | "authorized" | "not-authorized";
|
|
346
69
|
```
|
|
347
70
|
|
|
348
|
-
##
|
|
349
|
-
|
|
350
|
-
### Next.js App Router
|
|
71
|
+
## Utilities
|
|
351
72
|
|
|
352
73
|
```typescript
|
|
353
|
-
|
|
354
|
-
import { RenownUserProvider } from '@renown/sdk'
|
|
355
|
-
|
|
356
|
-
export default function RootLayout({ children }) {
|
|
357
|
-
return (
|
|
358
|
-
<html lang="en">
|
|
359
|
-
<body>
|
|
360
|
-
<RenownUserProvider>
|
|
361
|
-
{children}
|
|
362
|
-
</RenownUserProvider>
|
|
363
|
-
</body>
|
|
364
|
-
</html>
|
|
365
|
-
)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// components/Navbar.tsx - Using RenownAuthButton
|
|
369
|
-
'use client'
|
|
370
|
-
|
|
371
|
-
import { RenownAuthButton } from '@renown/sdk'
|
|
372
|
-
|
|
373
|
-
export function Navbar() {
|
|
374
|
-
return (
|
|
375
|
-
<nav>
|
|
376
|
-
<h1>My App</h1>
|
|
377
|
-
<RenownAuthButton showLogoutButton />
|
|
378
|
-
</nav>
|
|
379
|
-
)
|
|
380
|
-
}
|
|
74
|
+
import { parsePkhDid, verifyAuthBearerToken } from "@renown/sdk";
|
|
381
75
|
|
|
382
|
-
//
|
|
383
|
-
|
|
76
|
+
// Parse a DID:pkh string
|
|
77
|
+
const { networkId, chainId, address } = parsePkhDid("did:pkh:eip155:1:0x...");
|
|
384
78
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
export default function ProfilePage() {
|
|
388
|
-
const { user, openRenown, logout } = useUser()
|
|
389
|
-
|
|
390
|
-
if (!user) {
|
|
391
|
-
return (
|
|
392
|
-
<div>
|
|
393
|
-
<h1>Login Required</h1>
|
|
394
|
-
<button onClick={openRenown}>Login with Renown</button>
|
|
395
|
-
</div>
|
|
396
|
-
)
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
return (
|
|
400
|
-
<div>
|
|
401
|
-
<h1>Profile</h1>
|
|
402
|
-
<p>DID: {user.did}</p>
|
|
403
|
-
<p>Name: {user.name}</p>
|
|
404
|
-
<button onClick={logout}>Logout</button>
|
|
405
|
-
</div>
|
|
406
|
-
)
|
|
407
|
-
}
|
|
79
|
+
// Verify a bearer token
|
|
80
|
+
const result = await verifyAuthBearerToken(jwt); // false | AuthVerifiedCredential
|
|
408
81
|
```
|
|
409
82
|
|
|
410
|
-
|
|
83
|
+
## Node.js
|
|
411
84
|
|
|
412
|
-
|
|
413
|
-
// main.tsx
|
|
414
|
-
import { RenownUserProvider } from '@renown/sdk'
|
|
415
|
-
import App from './App'
|
|
416
|
-
|
|
417
|
-
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
418
|
-
<React.StrictMode>
|
|
419
|
-
<RenownUserProvider>
|
|
420
|
-
<App />
|
|
421
|
-
</RenownUserProvider>
|
|
422
|
-
</React.StrictMode>
|
|
423
|
-
)
|
|
424
|
-
|
|
425
|
-
// App.tsx - Using RenownAuthButton
|
|
426
|
-
import { RenownAuthButton } from '@renown/sdk'
|
|
427
|
-
|
|
428
|
-
function App() {
|
|
429
|
-
return (
|
|
430
|
-
<div>
|
|
431
|
-
<h1>My App</h1>
|
|
432
|
-
<RenownAuthButton showLogoutButton />
|
|
433
|
-
</div>
|
|
434
|
-
)
|
|
435
|
-
}
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
## Troubleshooting
|
|
439
|
-
|
|
440
|
-
### RenownUserProvider Context Error
|
|
441
|
-
|
|
442
|
-
**Error:** `useUser must be used within an RenownUserProvider`
|
|
443
|
-
|
|
444
|
-
**Solution:** Ensure your component is wrapped by `<RenownUserProvider>`:
|
|
85
|
+
For server-side usage, import from `@renown/sdk/node`:
|
|
445
86
|
|
|
446
87
|
```typescript
|
|
447
|
-
|
|
448
|
-
<YourComponent /> {/* ✅ Can use useUser */}
|
|
449
|
-
</RenownUserProvider>
|
|
88
|
+
import { RenownBuilder } from "@renown/sdk/node";
|
|
450
89
|
```
|
|
451
90
|
|
|
452
|
-
### Custom Renown URL
|
|
453
|
-
|
|
454
|
-
To use a different Renown instance:
|
|
455
|
-
|
|
456
|
-
```typescript
|
|
457
|
-
<RenownUserProvider renownUrl="https://your-renown-instance.com">
|
|
458
|
-
<App />
|
|
459
|
-
</RenownUserProvider>
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Session Not Persisting
|
|
463
|
-
|
|
464
|
-
If sessions aren't persisting across page reloads:
|
|
465
|
-
|
|
466
|
-
1. Check that sessionStorage is available (not in incognito mode)
|
|
467
|
-
2. Verify the session hasn't expired (24 hour timeout by default)
|
|
468
|
-
3. Check browser console for any errors during initialization
|
|
469
|
-
|
|
470
|
-
## Contributing
|
|
471
|
-
|
|
472
|
-
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
|
|
473
|
-
|
|
474
91
|
## License
|
|
475
92
|
|
|
476
93
|
AGPL-3.0-only
|
|
477
94
|
|
|
478
|
-
## Documentation
|
|
479
|
-
|
|
480
|
-
Full documentation is available in the Powerhouse Academy:
|
|
481
|
-
- [Overview & Quick Start](../../apps/academy/docs/academy/04-APIReferences/renown-sdk/00-Overview.md)
|
|
482
|
-
- [Authentication Guide](../../apps/academy/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md)
|
|
483
|
-
- [API Reference](../../apps/academy/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md)
|
|
484
|
-
|
|
485
95
|
## Support
|
|
486
96
|
|
|
487
|
-
For issues and questions:
|
|
488
97
|
- GitHub Issues: [powerhouse-inc/powerhouse](https://github.com/powerhouse-inc/powerhouse)
|
|
489
98
|
- Documentation: [Powerhouse Academy](https://docs.powerhouse.io)
|
package/dist/src/common.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
import type { CreateBearerTokenOptions } from "./
|
|
1
|
+
import { type IRenownCrypto } from "./crypto/index.js";
|
|
2
|
+
import { MemoryStorage } from "./storage/common.js";
|
|
3
|
+
import type { CreateBearerTokenOptions, IRenown, ISigner, LoginStatus, ProfileFetcher, RenownEventEmitter, RenownEvents, RenownStorage, RenownStorageMap, User } from "./types.js";
|
|
4
|
+
export * from "./constants.js";
|
|
5
|
+
export declare class RenownMemoryStorage extends MemoryStorage<RenownStorageMap> {
|
|
6
|
+
}
|
|
4
7
|
export declare class Renown implements IRenown {
|
|
5
8
|
#private;
|
|
6
|
-
constructor(store: RenownStorage, eventEmitter: RenownEventEmitter,
|
|
9
|
+
constructor(store: RenownStorage, eventEmitter: RenownEventEmitter, crypto: IRenownCrypto, appName: string, baseUrl?: string, profileFetcher?: ProfileFetcher);
|
|
10
|
+
get baseUrl(): string;
|
|
7
11
|
get user(): import("./types.js").InternalUser | undefined;
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
get status(): LoginStatus;
|
|
13
|
+
get signer(): ISigner;
|
|
14
|
+
get crypto(): IRenownCrypto;
|
|
15
|
+
get did(): `did:${string}`;
|
|
16
|
+
get profileFetcher(): ProfileFetcher | undefined;
|
|
17
|
+
login(userDid: string): Promise<User>;
|
|
10
18
|
logout(): Promise<void>;
|
|
11
19
|
on<K extends keyof RenownEvents>(event: K, listener: (data: RenownEvents[K]) => void): () => void;
|
|
12
|
-
verifyBearerToken(token: string): Promise<false | import("
|
|
13
|
-
|
|
20
|
+
verifyBearerToken(token: string): Promise<false | import("./types.js").AuthVerifiedCredential>;
|
|
21
|
+
getBearerToken(options: CreateBearerTokenOptions): Promise<string>;
|
|
14
22
|
}
|
|
15
23
|
//# sourceMappingURL=common.d.ts.map
|
package/dist/src/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EACV,wBAAwB,EACxB,OAAO,EACP,OAAO,EACP,WAAW,EAEX,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,IAAI,EACL,MAAM,YAAY,CAAC;AAEpB,cAAc,gBAAgB,CAAC;AAE/B,qBAAa,mBAAoB,SAAQ,aAAa,CAAC,gBAAgB,CAAC;CAAG;AAE3E,qBAAa,MAAO,YAAW,OAAO;;gBAWlC,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,SAAqB,EAC5B,cAAc,CAAC,EAAE,cAAc;IAejC,IAAI,OAAO,WAEV;IAED,IAAI,IAAI,kDAEP;IAED,IAAI,MAAM,gBAET;IAED,IAAI,MAAM,YAET;IAED,IAAI,MAAM,kBAET;IAED,IAAI,GAAG,oBAEN;IAED,IAAI,cAAc,+BAEjB;IAgBK,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgE3C,MAAM;IAMN,EAAE,CAAC,CAAC,SAAS,MAAM,YAAY,EAC7B,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,GACxC,MAAM,IAAI;IA6BP,iBAAiB,CAAC,KAAK,EAAE,MAAM;IAI/B,cAAc,CAAC,OAAO,EAAE,wBAAwB;CAMvD"}
|