shogun-button-react 1.5.20 → 1.5.22
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 +156 -39
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,6 +13,14 @@ A React component library for seamless integration of Shogun authentication into
|
|
|
13
13
|
- 📱 Responsive design
|
|
14
14
|
- 🌍 TypeScript support
|
|
15
15
|
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install shogun-button-react
|
|
20
|
+
# or
|
|
21
|
+
yarn add shogun-button-react
|
|
22
|
+
```
|
|
23
|
+
|
|
16
24
|
## Quick Start
|
|
17
25
|
|
|
18
26
|
```tsx
|
|
@@ -25,11 +33,27 @@ import {
|
|
|
25
33
|
import "shogun-button-react/styles.css";
|
|
26
34
|
|
|
27
35
|
function App() {
|
|
28
|
-
const { sdk, options
|
|
36
|
+
const { sdk, options } = shogunConnector({
|
|
29
37
|
appName: "My App",
|
|
30
38
|
appDescription: "An awesome app with Shogun authentication",
|
|
31
39
|
appUrl: "https://myapp.com",
|
|
32
40
|
appIcon: "https://myapp.com/icon.png",
|
|
41
|
+
// Enable authentication methods
|
|
42
|
+
showMetamask: true,
|
|
43
|
+
showWebauthn: true,
|
|
44
|
+
showNostr: true,
|
|
45
|
+
showOauth: true,
|
|
46
|
+
// Network configuration
|
|
47
|
+
peers: ["https://gun-manhattan.herokuapp.com/gun"],
|
|
48
|
+
// OAuth providers (optional)
|
|
49
|
+
oauth: {
|
|
50
|
+
providers: {
|
|
51
|
+
google: {
|
|
52
|
+
clientId: "YOUR_GOOGLE_CLIENT_ID",
|
|
53
|
+
redirectUri: "http://localhost:3000/auth/callback",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
33
57
|
});
|
|
34
58
|
|
|
35
59
|
return (
|
|
@@ -45,6 +69,9 @@ function App() {
|
|
|
45
69
|
onError={(error) => {
|
|
46
70
|
console.error("An error occurred:", error);
|
|
47
71
|
}}
|
|
72
|
+
onLogout={() => {
|
|
73
|
+
console.log("User logged out");
|
|
74
|
+
}}
|
|
48
75
|
>
|
|
49
76
|
<div>
|
|
50
77
|
<h1>Welcome to My App</h1>
|
|
@@ -65,13 +92,14 @@ The provider component that supplies Shogun context to your application.
|
|
|
65
92
|
|
|
66
93
|
#### Props
|
|
67
94
|
|
|
68
|
-
| Name | Type
|
|
69
|
-
| --------------- |
|
|
70
|
-
| sdk | ShogunCore
|
|
71
|
-
| options |
|
|
95
|
+
| Name | Type | Description |
|
|
96
|
+
| --------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------- |
|
|
97
|
+
| sdk | ShogunCore | Shogun SDK instance created by shogunConnector |
|
|
98
|
+
| options | ShogunConnectorOptions | Configuration options |
|
|
72
99
|
| onLoginSuccess | (data: { userPub: string; username: string; password?: string; authMethod?: string }) => void | Callback fired on successful login |
|
|
73
100
|
| onSignupSuccess | (data: { userPub: string; username: string; password?: string; authMethod?: string }) => void | Callback fired on successful signup |
|
|
74
|
-
| onError | (error:
|
|
101
|
+
| onError | (error: string) => void | Callback fired when an error occurs |
|
|
102
|
+
| onLogout | () => void | Callback fired when user logs out |
|
|
75
103
|
|
|
76
104
|
### ShogunButton
|
|
77
105
|
|
|
@@ -93,7 +121,6 @@ function Profile() {
|
|
|
93
121
|
login,
|
|
94
122
|
signup,
|
|
95
123
|
logout,
|
|
96
|
-
setProvider,
|
|
97
124
|
hasPlugin,
|
|
98
125
|
getPlugin,
|
|
99
126
|
exportGunPair,
|
|
@@ -104,37 +131,35 @@ function Profile() {
|
|
|
104
131
|
const handleLogin = async () => {
|
|
105
132
|
// Login with username/password
|
|
106
133
|
await login("password", "username", "password");
|
|
107
|
-
|
|
134
|
+
|
|
108
135
|
// Or login with MetaMask
|
|
109
136
|
await login("web3");
|
|
110
|
-
|
|
137
|
+
|
|
111
138
|
// Or login with WebAuthn
|
|
112
139
|
await login("webauthn", "username");
|
|
113
|
-
|
|
140
|
+
|
|
114
141
|
// Or login with Nostr
|
|
115
142
|
await login("nostr");
|
|
116
|
-
|
|
143
|
+
|
|
117
144
|
// Or login with OAuth
|
|
118
145
|
await login("oauth", "google");
|
|
119
|
-
|
|
146
|
+
|
|
120
147
|
// Or login with Gun pair (for account recovery)
|
|
121
|
-
const pairData = {
|
|
148
|
+
const pairData = {
|
|
149
|
+
/* Gun pair object */
|
|
150
|
+
};
|
|
122
151
|
await login("pair", pairData);
|
|
123
152
|
};
|
|
124
153
|
|
|
125
154
|
const handleSignUp = async () => {
|
|
126
155
|
// Sign up with username/password
|
|
127
156
|
await signup("password", "newusername", "newpassword");
|
|
128
|
-
|
|
157
|
+
|
|
129
158
|
// Or sign up with other methods (similar to login)
|
|
130
159
|
await signup("web3");
|
|
131
160
|
await signup("webauthn", "newusername");
|
|
132
161
|
};
|
|
133
162
|
|
|
134
|
-
const switchToCustomNetwork = () => {
|
|
135
|
-
setProvider('https://my-custom-rpc.example.com');
|
|
136
|
-
};
|
|
137
|
-
|
|
138
163
|
const handleExportPair = async () => {
|
|
139
164
|
try {
|
|
140
165
|
const pairData = await exportGunPair("optional-encryption-password");
|
|
@@ -159,10 +184,10 @@ function Profile() {
|
|
|
159
184
|
// Observe reactive data changes
|
|
160
185
|
useEffect(() => {
|
|
161
186
|
if (isLoggedIn) {
|
|
162
|
-
const subscription = observe<any>(
|
|
163
|
-
console.log(
|
|
187
|
+
const subscription = observe<any>("user/profile").subscribe((data) => {
|
|
188
|
+
console.log("Profile data updated:", data);
|
|
164
189
|
});
|
|
165
|
-
|
|
190
|
+
|
|
166
191
|
return () => subscription.unsubscribe();
|
|
167
192
|
}
|
|
168
193
|
}, [isLoggedIn, observe]);
|
|
@@ -172,7 +197,6 @@ function Profile() {
|
|
|
172
197
|
<h2>Welcome, {username}!</h2>
|
|
173
198
|
<p>User Public Key: {userPub}</p>
|
|
174
199
|
<button onClick={logout}>Logout</button>
|
|
175
|
-
<button onClick={switchToCustomNetwork}>Switch Network</button>
|
|
176
200
|
<button onClick={handleExportPair}>Export Account</button>
|
|
177
201
|
</div>
|
|
178
202
|
) : (
|
|
@@ -192,38 +216,37 @@ interface ShogunConnectorOptions {
|
|
|
192
216
|
appDescription?: string;
|
|
193
217
|
appUrl?: string;
|
|
194
218
|
appIcon?: string;
|
|
195
|
-
|
|
219
|
+
|
|
196
220
|
// Feature toggles
|
|
197
221
|
showMetamask?: boolean;
|
|
198
222
|
showWebauthn?: boolean;
|
|
199
223
|
showNostr?: boolean;
|
|
200
224
|
showOauth?: boolean;
|
|
201
225
|
darkMode?: boolean;
|
|
202
|
-
|
|
226
|
+
|
|
203
227
|
// Network configuration
|
|
204
228
|
websocketSecure?: boolean;
|
|
205
229
|
providerUrl?: string | null;
|
|
206
230
|
peers?: string[];
|
|
207
231
|
authToken?: string;
|
|
208
232
|
gunInstance?: IGunInstance<any>;
|
|
209
|
-
|
|
233
|
+
|
|
210
234
|
// Advanced options
|
|
211
|
-
logging?: {
|
|
212
|
-
enabled: boolean;
|
|
213
|
-
level: "error" | "warning" | "info" | "debug";
|
|
214
|
-
};
|
|
215
235
|
timeouts?: {
|
|
216
236
|
login?: number;
|
|
217
237
|
signup?: number;
|
|
218
238
|
operation?: number;
|
|
219
239
|
};
|
|
220
240
|
oauth?: {
|
|
221
|
-
providers: Record<
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
241
|
+
providers: Record<
|
|
242
|
+
string,
|
|
243
|
+
{
|
|
244
|
+
clientId: string;
|
|
245
|
+
clientSecret?: string;
|
|
246
|
+
redirectUri?: string;
|
|
247
|
+
}
|
|
248
|
+
>;
|
|
249
|
+
};
|
|
227
250
|
}
|
|
228
251
|
```
|
|
229
252
|
|
|
@@ -233,14 +256,86 @@ The `shogunConnector` returns an object with the following properties:
|
|
|
233
256
|
interface ShogunConnectorResult {
|
|
234
257
|
sdk: ShogunCore;
|
|
235
258
|
options: ShogunConnectorOptions;
|
|
236
|
-
setProvider: (provider: string | EthersProvider) => boolean;
|
|
237
|
-
getCurrentProviderUrl: () => string | null;
|
|
238
259
|
registerPlugin: (plugin: any) => boolean;
|
|
239
260
|
hasPlugin: (name: string) => boolean;
|
|
240
261
|
}
|
|
241
262
|
```
|
|
242
263
|
|
|
243
|
-
|
|
264
|
+
## Authentication Methods
|
|
265
|
+
|
|
266
|
+
### Password Authentication
|
|
267
|
+
|
|
268
|
+
```tsx
|
|
269
|
+
// Login
|
|
270
|
+
await login("password", "username", "password");
|
|
271
|
+
|
|
272
|
+
// Sign up
|
|
273
|
+
await signup("password", "username", "password");
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Web3 Authentication (MetaMask)
|
|
277
|
+
|
|
278
|
+
```tsx
|
|
279
|
+
// Login with MetaMask
|
|
280
|
+
await login("web3");
|
|
281
|
+
|
|
282
|
+
// Sign up with MetaMask
|
|
283
|
+
await signup("web3");
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### WebAuthn Authentication
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
// Login with WebAuthn
|
|
290
|
+
await login("webauthn", "username");
|
|
291
|
+
|
|
292
|
+
// Sign up with WebAuthn
|
|
293
|
+
await signup("webauthn", "username");
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Nostr Authentication
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
// Login with Nostr
|
|
300
|
+
await login("nostr");
|
|
301
|
+
|
|
302
|
+
// Sign up with Nostr
|
|
303
|
+
await signup("nostr");
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### OAuth Authentication
|
|
307
|
+
|
|
308
|
+
```tsx
|
|
309
|
+
// Login with OAuth provider
|
|
310
|
+
await login("oauth", "google");
|
|
311
|
+
|
|
312
|
+
// Sign up with OAuth provider
|
|
313
|
+
await signup("oauth", "google");
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Account Recovery (Gun Pair)
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
// Login with exported pair
|
|
320
|
+
await login("pair", pairData);
|
|
321
|
+
|
|
322
|
+
// Sign up with pair
|
|
323
|
+
await signup("pair", pairData);
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## Plugin Management
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
const { hasPlugin, getPlugin } = useShogun();
|
|
330
|
+
|
|
331
|
+
// Check if a plugin is available
|
|
332
|
+
if (hasPlugin("web3")) {
|
|
333
|
+
const web3Plugin = getPlugin("web3");
|
|
334
|
+
// Use the plugin
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Available plugins: "web3", "webauthn", "nostr", "oauth"
|
|
338
|
+
```
|
|
244
339
|
|
|
245
340
|
## Styling
|
|
246
341
|
|
|
@@ -252,10 +347,25 @@ The component comes with default styling that you can override using CSS variabl
|
|
|
252
347
|
--shogun-button-hover: #3f51b5;
|
|
253
348
|
--shogun-text-primary: #333333;
|
|
254
349
|
--shogun-background: #ffffff;
|
|
255
|
-
|
|
350
|
+
--shogun-border-radius: 8px;
|
|
351
|
+
--shogun-font-family:
|
|
352
|
+
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
353
|
+
--shogun-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
354
|
+
--shogun-transition: all 0.2s ease-in-out;
|
|
256
355
|
}
|
|
257
356
|
```
|
|
258
357
|
|
|
358
|
+
### Dark Mode
|
|
359
|
+
|
|
360
|
+
Enable dark mode by setting the `darkMode` option to `true`:
|
|
361
|
+
|
|
362
|
+
```tsx
|
|
363
|
+
const { sdk, options } = shogunConnector({
|
|
364
|
+
appName: "My App",
|
|
365
|
+
darkMode: true, // Enable dark mode
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
259
369
|
## Browser Support
|
|
260
370
|
|
|
261
371
|
- Chrome ≥ 60
|
|
@@ -263,6 +373,13 @@ The component comes with default styling that you can override using CSS variabl
|
|
|
263
373
|
- Safari ≥ 12
|
|
264
374
|
- Edge ≥ 79
|
|
265
375
|
|
|
376
|
+
## Dependencies
|
|
377
|
+
|
|
378
|
+
- React ≥ 18.0.0
|
|
379
|
+
- shogun-core ≥ 1.5.19
|
|
380
|
+
- ethers ≥ 6.13.5
|
|
381
|
+
- rxjs ≥ 7.8.1
|
|
382
|
+
|
|
266
383
|
## Contributing
|
|
267
384
|
|
|
268
385
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-button-react",
|
|
3
3
|
"description": "Shogun connector button",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.22",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"src/styles/index.css"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"ethers": "^6.13.5",
|
|
35
35
|
"prettier": "^3.5.3",
|
|
36
36
|
"rxjs": "^7.8.1",
|
|
37
|
-
"shogun-core": "^1.
|
|
37
|
+
"shogun-core": "^1.6.12"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "^18.0.0",
|