shogun-button-react 1.3.2 → 1.3.8
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/CHANGELOG.md +54 -0
- package/README.md +113 -33
- package/dist/components/ShogunButton.js +122 -76
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/styles/index.css +13 -315
- package/package.json +2 -2
- package/src/styles/index.css +13 -315
- package/dist/index.css +0 -756
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Version 1.3.4 (Latest)
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
- **Export Gun Pair Fix**: Fixed issue where "Export Pair" option was not accessible from user dropdown - now works correctly without requiring disconnect
|
|
7
|
+
- **Modal Logic Improvement**: Enhanced modal rendering logic to allow export functionality when user is already authenticated
|
|
8
|
+
- **UX Enhancement**: Improved back button behavior in export modal - now properly closes modal when user is logged in instead of showing unnecessary auth options
|
|
9
|
+
|
|
10
|
+
### 🔧 Technical Changes
|
|
11
|
+
- Modified component render logic to show modal even when user is logged in
|
|
12
|
+
- Improved export form navigation for better user experience
|
|
13
|
+
- Reordered dropdown menu items for better flow (Export Pair before Disconnect)
|
|
14
|
+
|
|
15
|
+
## Version 1.3.3
|
|
16
|
+
|
|
17
|
+
### ✨ New Features
|
|
18
|
+
- **Import Gun Pair Login**: Aggiunta possibilità di effettuare login tramite importazione di un Gun pair esistente
|
|
19
|
+
- **Export Gun Pair**: Funzionalità per esportare il proprio Gun pair con opzione di crittografia tramite password
|
|
20
|
+
- **Improved UX**: Migliorata l'interfaccia utente con feedback visivi e messaggi informativi
|
|
21
|
+
|
|
22
|
+
### 🔧 Improvements
|
|
23
|
+
- **Navigation Fix**: Il toggle "Don't have account? Sign up" ora porta alla selezione dei metodi di autenticazione invece che direttamente al form password
|
|
24
|
+
- **Visual Feedback**: Sostituiti gli alert con feedback visivi eleganti per export/import
|
|
25
|
+
- **Better Icons**: Aggiunte icone SVG personalizzate per import/export
|
|
26
|
+
- **Auto-copy**: L'export del pair viene automaticamente copiato negli appunti (quando supportato dal browser)
|
|
27
|
+
- **Enhanced Security**: Messaggi informativi per guidare l'utente nell'uso sicuro delle funzionalità
|
|
28
|
+
|
|
29
|
+
### 🛠 Technical Changes
|
|
30
|
+
- Rimosso l'uso del metodo `on` non disponibile in ShogunCore
|
|
31
|
+
- Definiti tipi locali per `AuthResult` per compatibilità
|
|
32
|
+
- Migliorata gestione degli stati nel provider
|
|
33
|
+
- Aggiunto reset completo degli stati quando si chiude il modal
|
|
34
|
+
|
|
35
|
+
### 🎨 UI/UX Enhancements
|
|
36
|
+
- Box informativi colorati per import/export
|
|
37
|
+
- Feedback di successo con timer automatico
|
|
38
|
+
- Indicatori di caricamento migliorati
|
|
39
|
+
- Messaggi di fallback per browser senza supporto clipboard
|
|
40
|
+
|
|
41
|
+
## Version 1.3.2
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
- Basic Gun pair export/import functionality
|
|
45
|
+
- Multi-authentication support (Password, MetaMask, WebAuthn, Nostr, OAuth)
|
|
46
|
+
- Dark mode support
|
|
47
|
+
- Responsive design
|
|
48
|
+
|
|
49
|
+
## Version 1.3.1
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
- Initial release
|
|
53
|
+
- Basic authentication flow
|
|
54
|
+
- Provider integration
|
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ A React component library for seamless integration of Shogun authentication into
|
|
|
8
8
|
- 🎨 Customizable UI components
|
|
9
9
|
- 🔒 Secure authentication flow
|
|
10
10
|
- 🌓 Dark mode support
|
|
11
|
-
- 🔌 Multiple authentication methods (Username/Password, MetaMask, WebAuthn)
|
|
11
|
+
- 🔌 Multiple authentication methods (Username/Password, MetaMask, WebAuthn, Nostr, OAuth)
|
|
12
|
+
- 🔑 Account backup and recovery (Gun pair export/import)
|
|
12
13
|
- 📱 Responsive design
|
|
13
14
|
- 🌍 TypeScript support
|
|
14
15
|
|
|
@@ -20,8 +21,8 @@ import {
|
|
|
20
21
|
ShogunButton,
|
|
21
22
|
ShogunButtonProvider,
|
|
22
23
|
shogunConnector,
|
|
23
|
-
} from "
|
|
24
|
-
import "
|
|
24
|
+
} from "shogun-button-react";
|
|
25
|
+
import "shogun-button-react/styles.css";
|
|
25
26
|
|
|
26
27
|
function App() {
|
|
27
28
|
const { sdk, options, setProvider } = shogunConnector({
|
|
@@ -66,62 +67,113 @@ The provider component that supplies Shogun context to your application.
|
|
|
66
67
|
|
|
67
68
|
| Name | Type | Description |
|
|
68
69
|
| --------------- | ------------------------ | ---------------------------------------------- |
|
|
69
|
-
| sdk |
|
|
70
|
+
| sdk | ShogunCore | Shogun SDK instance created by shogunConnector |
|
|
70
71
|
| options | Object | Configuration options |
|
|
71
|
-
| onLoginSuccess | (data:
|
|
72
|
-
| onSignupSuccess | (data:
|
|
72
|
+
| onLoginSuccess | (data: { userPub: string; username: string; password?: string; authMethod?: string }) => void | Callback fired on successful login |
|
|
73
|
+
| onSignupSuccess | (data: { userPub: string; username: string; password?: string; authMethod?: string }) => void | Callback fired on successful signup |
|
|
73
74
|
| onError | (error: Error) => void | Callback fired when an error occurs |
|
|
74
75
|
|
|
75
76
|
### ShogunButton
|
|
76
77
|
|
|
77
|
-
The main button component for triggering Shogun authentication.
|
|
78
|
-
|
|
79
|
-
#### Custom Button
|
|
80
|
-
|
|
81
|
-
You can customize the button appearance using `ShogunButton.Custom`:
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
<ShogunButton.Custom>
|
|
85
|
-
{({ ready, authenticate }) => (
|
|
86
|
-
<button
|
|
87
|
-
className="my-custom-button"
|
|
88
|
-
disabled={!ready}
|
|
89
|
-
onClick={authenticate}
|
|
90
|
-
>
|
|
91
|
-
Connect with Shogun
|
|
92
|
-
</button>
|
|
93
|
-
)}
|
|
94
|
-
</ShogunButton.Custom>
|
|
95
|
-
```
|
|
78
|
+
The main button component for triggering Shogun authentication. The component provides a complete authentication UI with modal dialogs for login and signup.
|
|
96
79
|
|
|
97
80
|
### useShogun Hook
|
|
98
81
|
|
|
99
82
|
A hook to access Shogun authentication state and functions.
|
|
100
83
|
|
|
101
84
|
```tsx
|
|
102
|
-
import {
|
|
85
|
+
import React, { useEffect } from "react";
|
|
86
|
+
import { useShogun } from "shogun-button-react";
|
|
103
87
|
|
|
104
88
|
function Profile() {
|
|
105
89
|
const {
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
isLoggedIn,
|
|
91
|
+
userPub,
|
|
92
|
+
username,
|
|
108
93
|
login,
|
|
109
94
|
signup,
|
|
110
95
|
logout,
|
|
111
|
-
connectWithMetaMask,
|
|
112
|
-
connectWithWebAuthn,
|
|
113
96
|
setProvider,
|
|
97
|
+
hasPlugin,
|
|
98
|
+
getPlugin,
|
|
99
|
+
exportGunPair,
|
|
100
|
+
importGunPair,
|
|
101
|
+
observe,
|
|
114
102
|
} = useShogun();
|
|
115
103
|
|
|
104
|
+
const handleLogin = async () => {
|
|
105
|
+
// Login with username/password
|
|
106
|
+
await login("password", "username", "password");
|
|
107
|
+
|
|
108
|
+
// Or login with MetaMask
|
|
109
|
+
await login("web3");
|
|
110
|
+
|
|
111
|
+
// Or login with WebAuthn
|
|
112
|
+
await login("webauthn", "username");
|
|
113
|
+
|
|
114
|
+
// Or login with Nostr
|
|
115
|
+
await login("nostr");
|
|
116
|
+
|
|
117
|
+
// Or login with OAuth
|
|
118
|
+
await login("oauth", "google");
|
|
119
|
+
|
|
120
|
+
// Or login with Gun pair (for account recovery)
|
|
121
|
+
const pairData = { /* Gun pair object */ };
|
|
122
|
+
await login("pair", pairData);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const handleSignUp = async () => {
|
|
126
|
+
// Sign up with username/password
|
|
127
|
+
await signup("password", "newusername", "newpassword");
|
|
128
|
+
|
|
129
|
+
// Or sign up with other methods (similar to login)
|
|
130
|
+
await signup("web3");
|
|
131
|
+
await signup("webauthn", "newusername");
|
|
132
|
+
};
|
|
133
|
+
|
|
116
134
|
const switchToCustomNetwork = () => {
|
|
117
135
|
setProvider('https://my-custom-rpc.example.com');
|
|
118
136
|
};
|
|
119
137
|
|
|
120
|
-
|
|
138
|
+
const handleExportPair = async () => {
|
|
139
|
+
try {
|
|
140
|
+
const pairData = await exportGunPair("optional-encryption-password");
|
|
141
|
+
console.log("Exported pair:", pairData);
|
|
142
|
+
// Save this data securely for account recovery
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error("Export failed:", error);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const handleImportPair = async () => {
|
|
149
|
+
try {
|
|
150
|
+
const success = await importGunPair(savedPairData, "optional-password");
|
|
151
|
+
if (success) {
|
|
152
|
+
console.log("Pair imported successfully");
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error("Import failed:", error);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Observe reactive data changes
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (isLoggedIn) {
|
|
162
|
+
const subscription = observe<any>('user/profile').subscribe(data => {
|
|
163
|
+
console.log('Profile data updated:', data);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return () => subscription.unsubscribe();
|
|
167
|
+
}
|
|
168
|
+
}, [isLoggedIn, observe]);
|
|
169
|
+
|
|
170
|
+
return isLoggedIn ? (
|
|
121
171
|
<div>
|
|
122
|
-
<h2>Welcome, {
|
|
172
|
+
<h2>Welcome, {username}!</h2>
|
|
173
|
+
<p>User Public Key: {userPub}</p>
|
|
123
174
|
<button onClick={logout}>Logout</button>
|
|
124
175
|
<button onClick={switchToCustomNetwork}>Switch Network</button>
|
|
176
|
+
<button onClick={handleExportPair}>Export Account</button>
|
|
125
177
|
</div>
|
|
126
178
|
) : (
|
|
127
179
|
<div>Please login to continue</div>
|
|
@@ -135,17 +187,43 @@ The `shogunConnector` accepts the following options:
|
|
|
135
187
|
|
|
136
188
|
```typescript
|
|
137
189
|
interface ShogunConnectorOptions {
|
|
190
|
+
// App information
|
|
138
191
|
appName: string;
|
|
139
192
|
appDescription?: string;
|
|
140
193
|
appUrl?: string;
|
|
141
194
|
appIcon?: string;
|
|
195
|
+
|
|
196
|
+
// Feature toggles
|
|
142
197
|
showMetamask?: boolean;
|
|
143
198
|
showWebauthn?: boolean;
|
|
199
|
+
showNostr?: boolean;
|
|
200
|
+
showOauth?: boolean;
|
|
144
201
|
darkMode?: boolean;
|
|
202
|
+
|
|
203
|
+
// Network configuration
|
|
145
204
|
websocketSecure?: boolean;
|
|
146
|
-
didRegistryAddress?: string | null;
|
|
147
205
|
providerUrl?: string | null;
|
|
148
206
|
peers?: string[];
|
|
207
|
+
authToken?: string;
|
|
208
|
+
gunInstance?: IGunInstance<any>;
|
|
209
|
+
|
|
210
|
+
// Advanced options
|
|
211
|
+
logging?: {
|
|
212
|
+
enabled: boolean;
|
|
213
|
+
level: "error" | "warning" | "info" | "debug";
|
|
214
|
+
};
|
|
215
|
+
timeouts?: {
|
|
216
|
+
login?: number;
|
|
217
|
+
signup?: number;
|
|
218
|
+
operation?: number;
|
|
219
|
+
};
|
|
220
|
+
oauth?: {
|
|
221
|
+
providers: Record<string, {
|
|
222
|
+
clientId: string;
|
|
223
|
+
clientSecret?: string;
|
|
224
|
+
redirectUri?: string;
|
|
225
|
+
}>
|
|
226
|
+
}
|
|
149
227
|
}
|
|
150
228
|
```
|
|
151
229
|
|
|
@@ -157,6 +235,8 @@ interface ShogunConnectorResult {
|
|
|
157
235
|
options: ShogunConnectorOptions;
|
|
158
236
|
setProvider: (provider: string | EthersProvider) => boolean;
|
|
159
237
|
getCurrentProviderUrl: () => string | null;
|
|
238
|
+
registerPlugin: (plugin: any) => boolean;
|
|
239
|
+
hasPlugin: (name: string) => boolean;
|
|
160
240
|
}
|
|
161
241
|
```
|
|
162
242
|
|