@powerhousedao/switchboard 6.0.0-dev.11 → 6.0.0-dev.110
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/Auth.md +45 -27
- package/CHANGELOG.md +923 -5
- package/Dockerfile +4 -4
- package/README.md +13 -12
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/index.js +33 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/metrics.d.ts +7 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +34 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/profiler.d.ts +6 -1
- package/dist/src/profiler.d.ts.map +1 -1
- package/dist/src/profiler.js +31 -5
- package/dist/src/profiler.js.map +1 -1
- package/dist/src/renown.d.ts +16 -0
- package/dist/src/renown.d.ts.map +1 -0
- package/dist/src/renown.js +33 -0
- package/dist/src/renown.js.map +1 -0
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +135 -140
- package/dist/src/server.js.map +1 -1
- package/dist/src/types.d.ts +25 -18
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -32
- package/dist/src/utils.js.map +1 -1
- package/dist/test/metrics.test.d.ts +2 -0
- package/dist/test/metrics.test.d.ts.map +1 -0
- package/dist/test/metrics.test.js +121 -0
- package/dist/test/metrics.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +15 -0
- package/dist/vitest.config.js.map +1 -0
- package/package.json +31 -22
- package/test/metrics.test.ts +202 -0
- package/tsconfig.json +17 -4
- package/vitest.config.ts +15 -0
- package/dist/src/connect-crypto.d.ts +0 -41
- package/dist/src/connect-crypto.d.ts.map +0 -1
- package/dist/src/connect-crypto.js +0 -127
- package/dist/src/connect-crypto.js.map +0 -1
package/Auth.md
CHANGED
|
@@ -7,18 +7,21 @@ The Powerhouse authentication system is a sophisticated, decentralized identity
|
|
|
7
7
|
## What It's Capable Of
|
|
8
8
|
|
|
9
9
|
### 🔐 **Decentralized Identity Management**
|
|
10
|
+
|
|
10
11
|
- **DID (Decentralized Identifier) Creation**: Generates unique, self-sovereign identifiers based on Ethereum addresses
|
|
11
12
|
- **Verifiable Credentials**: Uses W3C Verifiable Credentials standard for cryptographic proof of identity
|
|
12
13
|
- **Wallet Integration**: Seamless integration with Ethereum wallets and other Web3 providers
|
|
13
14
|
- **Privacy Preservation**: Users can maintain pseudonymous identities while building reputation
|
|
14
15
|
|
|
15
16
|
### 🎭 **Role-Based Access Control (RBAC)**
|
|
17
|
+
|
|
16
18
|
- **Three-Tier System**: Guests, Users, and Admins with different permission levels
|
|
17
19
|
- **Flexible Configuration**: Easy setup through environment variables or configuration files
|
|
18
20
|
- **Granular Permissions**: Fine-grained control over what each role can access
|
|
19
21
|
- **Dynamic Role Assignment**: Roles can be updated without restarting the system
|
|
20
22
|
|
|
21
23
|
### 🔒 **Advanced Security Features**
|
|
24
|
+
|
|
22
25
|
- **Challenge-Response Authentication**: Cryptographic proof of wallet ownership
|
|
23
26
|
- **JWT Token Management**: Secure session handling with automatic expiration
|
|
24
27
|
- **Credential Verification**: Real-time validation against the Renown API
|
|
@@ -26,6 +29,7 @@ The Powerhouse authentication system is a sophisticated, decentralized identity
|
|
|
26
29
|
- **Session Management**: Multiple active sessions with individual controls
|
|
27
30
|
|
|
28
31
|
### 🌐 **Cross-Platform Compatibility**
|
|
32
|
+
|
|
29
33
|
- **GraphQL Integration**: Native GraphQL support with authentication middleware
|
|
30
34
|
- **REST API Support**: Standard HTTP authentication headers
|
|
31
35
|
- **Multi-Origin Support**: Configurable CORS and origin restrictions
|
|
@@ -49,13 +53,14 @@ The system uses the **Renown** service to create and manage decentralized identi
|
|
|
49
53
|
```typescript
|
|
50
54
|
// DID Format: did:pkh:eip155:1:0x1234...
|
|
51
55
|
interface PKHDid {
|
|
52
|
-
networkId: string;
|
|
53
|
-
chainId: number;
|
|
56
|
+
networkId: string; // Network identifier (e.g., "mainnet")
|
|
57
|
+
chainId: number; // Blockchain chain ID (e.g., 1 for Ethereum mainnet)
|
|
54
58
|
address: `0x${string}`; // Ethereum wallet address
|
|
55
59
|
}
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
**Key Benefits:**
|
|
63
|
+
|
|
59
64
|
- **Self-Sovereign**: Users control their own identity without central authority
|
|
60
65
|
- **Portable**: Identity can be used across different applications
|
|
61
66
|
- **Verifiable**: Cryptographic proof of ownership and authenticity
|
|
@@ -78,6 +83,7 @@ const token = await solveChallenge(challenge.nonce, signature);
|
|
|
78
83
|
```
|
|
79
84
|
|
|
80
85
|
**Security Features:**
|
|
86
|
+
|
|
81
87
|
- **Nonce-based**: Prevents replay attacks
|
|
82
88
|
- **Cryptographic Proof**: Verifies wallet ownership
|
|
83
89
|
- **Time-limited**: Challenges expire quickly
|
|
@@ -96,13 +102,14 @@ interface VerifiableCredential {
|
|
|
96
102
|
networkId: string;
|
|
97
103
|
address: string;
|
|
98
104
|
};
|
|
99
|
-
issuer: string;
|
|
100
|
-
issuanceDate: string;
|
|
101
|
-
proof: object;
|
|
105
|
+
issuer: string; // DID of the credential issuer
|
|
106
|
+
issuanceDate: string; // When credential was created
|
|
107
|
+
proof: object; // Cryptographic proof of authenticity
|
|
102
108
|
}
|
|
103
109
|
```
|
|
104
110
|
|
|
105
111
|
**Verification Process:**
|
|
112
|
+
|
|
106
113
|
1. **Token Decoding**: Extract credential information from JWT
|
|
107
114
|
2. **Credential Validation**: Verify against W3C standards
|
|
108
115
|
3. **Issuer Verification**: Check credential issuer authenticity
|
|
@@ -116,13 +123,14 @@ The system implements a three-tier role system with configurable permissions:
|
|
|
116
123
|
```typescript
|
|
117
124
|
interface AuthConfig {
|
|
118
125
|
enabled: boolean;
|
|
119
|
-
guests: string[];
|
|
120
|
-
users: string[];
|
|
121
|
-
admins: string[];
|
|
126
|
+
guests: string[]; // Array of wallet addresses
|
|
127
|
+
users: string[]; // Array of wallet addresses
|
|
128
|
+
admins: string[]; // Array of wallet addresses
|
|
122
129
|
}
|
|
123
130
|
```
|
|
124
131
|
|
|
125
132
|
**Permission Levels:**
|
|
133
|
+
|
|
126
134
|
- **Guests**: Read-only access to public data
|
|
127
135
|
- **Users**: Standard access to most endpoints and operations
|
|
128
136
|
- **Admins**: Full access including administrative functions
|
|
@@ -146,6 +154,7 @@ interface Session {
|
|
|
146
154
|
```
|
|
147
155
|
|
|
148
156
|
**Session Features:**
|
|
157
|
+
|
|
149
158
|
- **Multiple Sessions**: Users can have several active sessions
|
|
150
159
|
- **Custom Names**: Human-readable session identifiers
|
|
151
160
|
- **Expiration Control**: Configurable session lifetimes
|
|
@@ -157,6 +166,7 @@ interface Session {
|
|
|
157
166
|
### 1. **Basic Configuration**
|
|
158
167
|
|
|
159
168
|
#### Environment Variables Method
|
|
169
|
+
|
|
160
170
|
```bash
|
|
161
171
|
# Enable authentication
|
|
162
172
|
export AUTH_ENABLED=true
|
|
@@ -168,6 +178,7 @@ export ADMINS="0x111,0x222,0x333"
|
|
|
168
178
|
```
|
|
169
179
|
|
|
170
180
|
#### Configuration File Method
|
|
181
|
+
|
|
171
182
|
```json
|
|
172
183
|
{
|
|
173
184
|
"auth": {
|
|
@@ -182,6 +193,7 @@ export ADMINS="0x111,0x222,0x333"
|
|
|
182
193
|
### 2. **Frontend Integration**
|
|
183
194
|
|
|
184
195
|
#### Using the useAuth Hook
|
|
196
|
+
|
|
185
197
|
```typescript
|
|
186
198
|
import useAuth from '../hooks/useAuth';
|
|
187
199
|
|
|
@@ -190,7 +202,7 @@ function LoginComponent() {
|
|
|
190
202
|
|
|
191
203
|
if (!isAuthorized) {
|
|
192
204
|
return (
|
|
193
|
-
<button
|
|
205
|
+
<button
|
|
194
206
|
onClick={signIn}
|
|
195
207
|
className="bg-orange-500 hover:bg-orange-600 text-white px-4 py-2 rounded"
|
|
196
208
|
>
|
|
@@ -209,14 +221,15 @@ function LoginComponent() {
|
|
|
209
221
|
```
|
|
210
222
|
|
|
211
223
|
#### Session Management
|
|
224
|
+
|
|
212
225
|
```typescript
|
|
213
226
|
const { createSession, revokeSession, sessions } = useAuth();
|
|
214
227
|
|
|
215
228
|
// Create a new session
|
|
216
229
|
const token = await createSession(
|
|
217
|
-
"My API Token",
|
|
218
|
-
3600,
|
|
219
|
-
"https://myapp.com"
|
|
230
|
+
"My API Token", // Session name
|
|
231
|
+
3600, // Expiry in seconds (1 hour)
|
|
232
|
+
"https://myapp.com", // Allowed origin
|
|
220
233
|
);
|
|
221
234
|
|
|
222
235
|
// Revoke a session
|
|
@@ -226,14 +239,15 @@ await revokeSession(sessionId);
|
|
|
226
239
|
### 3. **Backend Integration**
|
|
227
240
|
|
|
228
241
|
#### Express Middleware Setup
|
|
242
|
+
|
|
229
243
|
```typescript
|
|
230
|
-
import { AuthService } from
|
|
244
|
+
import { AuthService } from "@powerhousedao/reactor-api";
|
|
231
245
|
|
|
232
246
|
const authService = new AuthService({
|
|
233
247
|
enabled: true,
|
|
234
|
-
guests: [
|
|
235
|
-
users: [
|
|
236
|
-
admins: [
|
|
248
|
+
guests: ["0x789", "0xabc"],
|
|
249
|
+
users: ["0x123", "0x456"],
|
|
250
|
+
admins: ["0x111", "0x222"],
|
|
237
251
|
});
|
|
238
252
|
|
|
239
253
|
// Apply to all routes
|
|
@@ -242,10 +256,10 @@ app.use(async (req, res, next) => {
|
|
|
242
256
|
});
|
|
243
257
|
|
|
244
258
|
// Access user info in route handlers
|
|
245
|
-
app.post(
|
|
246
|
-
const user = req.user;
|
|
259
|
+
app.post("/api/data", (req, res) => {
|
|
260
|
+
const user = req.user; // Authenticated user object
|
|
247
261
|
const isAdmin = req.admins.includes(user.address);
|
|
248
|
-
|
|
262
|
+
|
|
249
263
|
if (isAdmin) {
|
|
250
264
|
// Admin-only operations
|
|
251
265
|
}
|
|
@@ -253,18 +267,20 @@ app.post('/api/data', (req, res) => {
|
|
|
253
267
|
```
|
|
254
268
|
|
|
255
269
|
#### GraphQL Context Integration
|
|
270
|
+
|
|
256
271
|
```typescript
|
|
257
272
|
const graphqlManager = new GraphQLManager(/* config */);
|
|
258
273
|
|
|
259
274
|
// Add auth context fields
|
|
260
275
|
graphqlManager.setAdditionalContextFields(
|
|
261
|
-
authService.getAdditionalContextFields()
|
|
276
|
+
authService.getAdditionalContextFields(),
|
|
262
277
|
);
|
|
263
278
|
```
|
|
264
279
|
|
|
265
280
|
### 4. **API Authentication**
|
|
266
281
|
|
|
267
282
|
#### HTTP Headers
|
|
283
|
+
|
|
268
284
|
```bash
|
|
269
285
|
# Include JWT token in Authorization header
|
|
270
286
|
curl -H "Authorization: Bearer <your-jwt-token>" \
|
|
@@ -272,6 +288,7 @@ curl -H "Authorization: Bearer <your-jwt-token>" \
|
|
|
272
288
|
```
|
|
273
289
|
|
|
274
290
|
#### GraphQL Queries
|
|
291
|
+
|
|
275
292
|
```typescript
|
|
276
293
|
// Apollo Client with auth link
|
|
277
294
|
const authLink = setContext((_, { headers }) => ({
|
|
@@ -290,23 +307,25 @@ const client = new ApolloClient({
|
|
|
290
307
|
### 5. **Advanced Features**
|
|
291
308
|
|
|
292
309
|
#### Custom Session Creation
|
|
310
|
+
|
|
293
311
|
```typescript
|
|
294
312
|
// Create a long-lived API token
|
|
295
313
|
const apiToken = await createSession(
|
|
296
314
|
"API Integration Token",
|
|
297
|
-
86400 * 30,
|
|
298
|
-
"*"
|
|
315
|
+
86400 * 30, // 30 days
|
|
316
|
+
"*", // Allow all origins
|
|
299
317
|
);
|
|
300
318
|
|
|
301
319
|
// Create a restricted session
|
|
302
320
|
const restrictedToken = await createSession(
|
|
303
321
|
"Mobile App Token",
|
|
304
|
-
86400 * 7,
|
|
305
|
-
"https://mobile.myapp.com"
|
|
322
|
+
86400 * 7, // 7 days
|
|
323
|
+
"https://mobile.myapp.com", // Restrict to mobile app
|
|
306
324
|
);
|
|
307
325
|
```
|
|
308
326
|
|
|
309
327
|
#### Role-Based Route Protection
|
|
328
|
+
|
|
310
329
|
```typescript
|
|
311
330
|
// Middleware for admin-only routes
|
|
312
331
|
const requireAdmin = (req, res, next) => {
|
|
@@ -316,7 +335,7 @@ const requireAdmin = (req, res, next) => {
|
|
|
316
335
|
next();
|
|
317
336
|
};
|
|
318
337
|
|
|
319
|
-
app.post(
|
|
338
|
+
app.post("/admin/users", requireAdmin, (req, res) => {
|
|
320
339
|
// Admin-only user management
|
|
321
340
|
});
|
|
322
341
|
```
|
|
@@ -367,7 +386,7 @@ Enable detailed logging for troubleshooting:
|
|
|
367
386
|
// Enable verbose logging
|
|
368
387
|
const authService = new AuthService({
|
|
369
388
|
enabled: true,
|
|
370
|
-
debug: true,
|
|
389
|
+
debug: true, // Enable debug logging
|
|
371
390
|
// ... other config
|
|
372
391
|
});
|
|
373
392
|
```
|
|
@@ -393,4 +412,3 @@ The Powerhouse authentication system provides a robust, secure, and flexible fou
|
|
|
393
412
|
Whether you're building a simple web app or a complex enterprise system, the authentication system scales to meet your needs while maintaining the highest security standards. The decentralized nature ensures user privacy and control, while the role-based system provides the administrative oversight needed for production applications.
|
|
394
413
|
|
|
395
414
|
For more information and advanced usage examples, refer to the Powerhouse documentation and community resources.
|
|
396
|
-
|