shogun-button-react 5.0.0 → 6.0.1
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 +752 -752
- package/dist/118.index.js +2 -0
- package/dist/118.index.js.LICENSE.txt +3 -0
- package/dist/122.index.js +2 -0
- package/dist/122.index.js.LICENSE.txt +1 -0
- package/dist/18.index.js +1 -0
- package/dist/195.index.js +2 -0
- package/dist/195.index.js.LICENSE.txt +1 -0
- package/dist/47.index.js +2 -0
- package/dist/47.index.js.LICENSE.txt +1 -0
- package/dist/508.index.js +2 -0
- package/dist/508.index.js.LICENSE.txt +1 -0
- package/dist/604.index.js +2 -0
- package/dist/604.index.js.LICENSE.txt +7 -0
- package/dist/619.index.js +2 -0
- package/dist/619.index.js.LICENSE.txt +1 -0
- package/dist/649.index.js +2 -0
- package/dist/649.index.js.LICENSE.txt +1 -0
- package/dist/695.index.js +1 -0
- package/dist/732.index.js +1 -0
- package/dist/794.index.js +2 -0
- package/dist/794.index.js.LICENSE.txt +1 -0
- package/dist/components/ShogunButton.d.ts +3 -3
- package/dist/components/ShogunButton.js +284 -131
- package/dist/connector.js +50 -41
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +0 -2
- package/dist/interfaces/connector-options.d.ts +5 -6
- package/package.json +2 -2
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React, { useContext, useState, createContext, useEffect, useRef, } from "react";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
import "../styles/index.css";
|
|
4
|
+
// Helper type to check if core is ShogunCore
|
|
5
|
+
function isShogunCore(core) {
|
|
6
|
+
return core && typeof core.isLoggedIn === 'function' && typeof core.gun !== 'undefined';
|
|
7
|
+
}
|
|
8
|
+
// Helper type to check if core is QuickStart
|
|
9
|
+
function isQuickStart(core) {
|
|
10
|
+
return core && typeof core.api !== 'undefined' && typeof core.database !== 'undefined';
|
|
11
|
+
}
|
|
4
12
|
// Default context
|
|
5
13
|
const defaultShogunContext = {
|
|
6
14
|
core: null,
|
|
@@ -38,14 +46,29 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
38
46
|
if (!core)
|
|
39
47
|
return;
|
|
40
48
|
// Verifichiamo se l'utente è già loggato all'inizializzazione
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
let isLoggedIn = false;
|
|
50
|
+
let pub = null;
|
|
51
|
+
if (isShogunCore(core)) {
|
|
52
|
+
isLoggedIn = core.isLoggedIn();
|
|
53
|
+
if (isLoggedIn) {
|
|
54
|
+
pub = (_b = (_a = core.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (isQuickStart(core)) {
|
|
58
|
+
// QuickStart doesn't have built-in login state, so we check sessionStorage
|
|
59
|
+
const pair = sessionStorage.getItem("gun/pair") || sessionStorage.getItem("pair");
|
|
60
|
+
isLoggedIn = !!pair;
|
|
61
|
+
if (isLoggedIn) {
|
|
62
|
+
// Try to get user info from the database
|
|
63
|
+
const userData = core.database.getCurrentUser();
|
|
64
|
+
pub = (userData === null || userData === void 0 ? void 0 : userData.pub) || null;
|
|
47
65
|
}
|
|
48
66
|
}
|
|
67
|
+
if (isLoggedIn && pub) {
|
|
68
|
+
setIsLoggedIn(true);
|
|
69
|
+
setUserPub(pub);
|
|
70
|
+
setUsername(pub.slice(0, 8) + "...");
|
|
71
|
+
}
|
|
49
72
|
// Poiché il metodo 'on' non esiste su ShogunCore,
|
|
50
73
|
// gestiamo gli stati direttamente nei metodi di login/logout
|
|
51
74
|
}, [core, onLoginSuccess]);
|
|
@@ -76,7 +99,16 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
76
99
|
case "password":
|
|
77
100
|
username = args[0];
|
|
78
101
|
console.log(`[DEBUG] ShogunButton: Calling core.login for username: ${username}`);
|
|
79
|
-
|
|
102
|
+
if (isShogunCore(core)) {
|
|
103
|
+
result = await core.login(args[0], args[1]);
|
|
104
|
+
}
|
|
105
|
+
else if (isQuickStart(core)) {
|
|
106
|
+
// Use QuickStart database directly
|
|
107
|
+
result = await core.database.login(args[0], args[1]);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error("Unsupported core type");
|
|
111
|
+
}
|
|
80
112
|
console.log(`[DEBUG] ShogunButton: core.login result:`, result);
|
|
81
113
|
break;
|
|
82
114
|
case "pair":
|
|
@@ -85,75 +117,103 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
85
117
|
if (!pair || typeof pair !== "object") {
|
|
86
118
|
throw new Error("Invalid pair data provided");
|
|
87
119
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
if (isShogunCore(core)) {
|
|
121
|
+
result = await new Promise((resolve, reject) => {
|
|
122
|
+
core.gun.user().auth(pair, (ack) => {
|
|
123
|
+
if (ack.err) {
|
|
124
|
+
reject(new Error(`Pair authentication failed: ${ack.err}`));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const pub = ack.pub || pair.pub;
|
|
128
|
+
const alias = ack.alias || `user_${pub === null || pub === void 0 ? void 0 : pub.substring(0, 8)}`;
|
|
129
|
+
resolve({
|
|
130
|
+
success: true,
|
|
131
|
+
userPub: pub,
|
|
132
|
+
alias: alias,
|
|
133
|
+
method: "pair",
|
|
134
|
+
});
|
|
101
135
|
});
|
|
102
136
|
});
|
|
103
|
-
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error("Pair authentication not supported with QuickStart");
|
|
140
|
+
}
|
|
104
141
|
username = result.alias;
|
|
105
142
|
authMethod = "pair";
|
|
106
143
|
break;
|
|
107
144
|
case "webauthn":
|
|
108
145
|
username = args[0];
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
146
|
+
if (isShogunCore(core)) {
|
|
147
|
+
const webauthn = core.getPlugin("webauthn");
|
|
148
|
+
if (!webauthn)
|
|
149
|
+
throw new Error("WebAuthn plugin not available");
|
|
150
|
+
result = await webauthn.login(username);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
throw new Error("WebAuthn not supported with QuickStart");
|
|
154
|
+
}
|
|
113
155
|
break;
|
|
114
156
|
case "web3":
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
157
|
+
if (isShogunCore(core)) {
|
|
158
|
+
const web3 = core.getPlugin("web3");
|
|
159
|
+
if (!web3)
|
|
160
|
+
throw new Error("Web3 plugin not available");
|
|
161
|
+
const connectionResult = await web3.connectMetaMask();
|
|
162
|
+
if (!connectionResult.success || !connectionResult.address) {
|
|
163
|
+
throw new Error(connectionResult.error || "Failed to connect wallet.");
|
|
164
|
+
}
|
|
165
|
+
username = connectionResult.address;
|
|
166
|
+
result = await web3.login(connectionResult.address);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
throw new Error("Web3 not supported with QuickStart");
|
|
121
170
|
}
|
|
122
|
-
username = connectionResult.address;
|
|
123
|
-
result = await web3.login(connectionResult.address);
|
|
124
171
|
break;
|
|
125
172
|
case "nostr":
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
173
|
+
if (isShogunCore(core)) {
|
|
174
|
+
const nostr = core.getPlugin("nostr");
|
|
175
|
+
if (!nostr)
|
|
176
|
+
throw new Error("Nostr plugin not available");
|
|
177
|
+
const nostrResult = await nostr.connectBitcoinWallet();
|
|
178
|
+
if (!nostrResult || !nostrResult.success) {
|
|
179
|
+
throw new Error((nostrResult === null || nostrResult === void 0 ? void 0 : nostrResult.error) || "Connessione al wallet Bitcoin fallita");
|
|
180
|
+
}
|
|
181
|
+
const pubkey = nostrResult.address;
|
|
182
|
+
if (!pubkey)
|
|
183
|
+
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
184
|
+
username = pubkey;
|
|
185
|
+
result = await nostr.login(pubkey);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new Error("Nostr not supported with QuickStart");
|
|
132
189
|
}
|
|
133
|
-
const pubkey = nostrResult.address;
|
|
134
|
-
if (!pubkey)
|
|
135
|
-
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
136
|
-
username = pubkey;
|
|
137
|
-
result = await nostr.login(pubkey);
|
|
138
190
|
break;
|
|
139
191
|
case "zkproof":
|
|
140
192
|
const trapdoor = args[0];
|
|
141
193
|
if (!trapdoor || typeof trapdoor !== "string") {
|
|
142
194
|
throw new Error("Invalid trapdoor provided");
|
|
143
195
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
196
|
+
if (isShogunCore(core)) {
|
|
197
|
+
const zkproof = core.getPlugin("zkproof");
|
|
198
|
+
if (!zkproof)
|
|
199
|
+
throw new Error("ZK-Proof plugin not available");
|
|
200
|
+
const zkLoginResult = await zkproof.login(trapdoor);
|
|
201
|
+
result = zkLoginResult;
|
|
202
|
+
username = zkLoginResult.username || zkLoginResult.alias || `zk_${(zkLoginResult.userPub || "").slice(0, 16)}`;
|
|
203
|
+
authMethod = "zkproof";
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
throw new Error("ZK-Proof not supported with QuickStart");
|
|
207
|
+
}
|
|
151
208
|
break;
|
|
152
209
|
default:
|
|
153
210
|
throw new Error("Unsupported login method");
|
|
154
211
|
}
|
|
155
212
|
if (result.success) {
|
|
156
|
-
|
|
213
|
+
let userPub = result.userPub || "";
|
|
214
|
+
if (!userPub && isShogunCore(core)) {
|
|
215
|
+
userPub = ((_b = (_a = core.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub) || "";
|
|
216
|
+
}
|
|
157
217
|
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
158
218
|
setIsLoggedIn(true);
|
|
159
219
|
setUserPub(userPub);
|
|
@@ -192,10 +252,17 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
192
252
|
}
|
|
193
253
|
console.log(`[DEBUG] ShogunButton: Calling core.signUp for username: ${username}`);
|
|
194
254
|
console.log(`[DEBUG] ShogunButton: core object:`, core);
|
|
195
|
-
console.log(`[DEBUG] ShogunButton: core.signUp exists:`, typeof (core === null || core === void 0 ? void 0 : core.signUp));
|
|
196
255
|
try {
|
|
197
256
|
console.log(`[DEBUG] ShogunButton: About to call core.signUp...`);
|
|
198
|
-
|
|
257
|
+
if (isShogunCore(core)) {
|
|
258
|
+
result = await core.signUp(args[0], args[1]);
|
|
259
|
+
}
|
|
260
|
+
else if (isQuickStart(core)) {
|
|
261
|
+
result = await core.database.signUp(args[0], args[1]);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
throw new Error("Unsupported core type");
|
|
265
|
+
}
|
|
199
266
|
console.log(`[DEBUG] ShogunButton: core.signUp completed successfully`);
|
|
200
267
|
console.log(`[DEBUG] ShogunButton: core.signUp result:`, result);
|
|
201
268
|
}
|
|
@@ -206,51 +273,74 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
206
273
|
break;
|
|
207
274
|
case "webauthn":
|
|
208
275
|
username = args[0];
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
276
|
+
if (isShogunCore(core)) {
|
|
277
|
+
const webauthn = core.getPlugin("webauthn");
|
|
278
|
+
if (!webauthn)
|
|
279
|
+
throw new Error("WebAuthn plugin not available");
|
|
280
|
+
result = await webauthn.signUp(username, { generateSeedPhrase: true });
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
throw new Error("WebAuthn not supported with QuickStart");
|
|
284
|
+
}
|
|
213
285
|
break;
|
|
214
286
|
case "web3":
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
287
|
+
if (isShogunCore(core)) {
|
|
288
|
+
const web3 = core.getPlugin("web3");
|
|
289
|
+
if (!web3)
|
|
290
|
+
throw new Error("Web3 plugin not available");
|
|
291
|
+
const connectionResult = await web3.connectMetaMask();
|
|
292
|
+
if (!connectionResult.success || !connectionResult.address) {
|
|
293
|
+
throw new Error(connectionResult.error || "Failed to connect wallet.");
|
|
294
|
+
}
|
|
295
|
+
username = connectionResult.address;
|
|
296
|
+
result = await web3.signUp(connectionResult.address);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
throw new Error("Web3 not supported with QuickStart");
|
|
221
300
|
}
|
|
222
|
-
username = connectionResult.address;
|
|
223
|
-
result = await web3.signUp(connectionResult.address);
|
|
224
301
|
break;
|
|
225
302
|
case "nostr":
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
303
|
+
if (isShogunCore(core)) {
|
|
304
|
+
const nostr = core.getPlugin("nostr");
|
|
305
|
+
if (!nostr)
|
|
306
|
+
throw new Error("Nostr plugin not available");
|
|
307
|
+
const nostrResult = await nostr.connectBitcoinWallet();
|
|
308
|
+
if (!nostrResult || !nostrResult.success) {
|
|
309
|
+
throw new Error((nostrResult === null || nostrResult === void 0 ? void 0 : nostrResult.error) || "Connessione al wallet Bitcoin fallita");
|
|
310
|
+
}
|
|
311
|
+
const pubkey = nostrResult.address;
|
|
312
|
+
if (!pubkey)
|
|
313
|
+
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
314
|
+
username = pubkey;
|
|
315
|
+
result = await nostr.signUp(pubkey);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
throw new Error("Nostr not supported with QuickStart");
|
|
232
319
|
}
|
|
233
|
-
const pubkey = nostrResult.address;
|
|
234
|
-
if (!pubkey)
|
|
235
|
-
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
236
|
-
username = pubkey;
|
|
237
|
-
result = await nostr.signUp(pubkey);
|
|
238
320
|
break;
|
|
239
321
|
case "zkproof":
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
322
|
+
if (isShogunCore(core)) {
|
|
323
|
+
const zkproofPlugin = core.getPlugin("zkproof");
|
|
324
|
+
if (!zkproofPlugin)
|
|
325
|
+
throw new Error("ZK-Proof plugin not available");
|
|
326
|
+
const seed = args[0]; // Optional seed
|
|
327
|
+
const zkSignupResult = await zkproofPlugin.signUp(seed);
|
|
328
|
+
result = zkSignupResult;
|
|
329
|
+
username = zkSignupResult.username || zkSignupResult.alias || `zk_${(zkSignupResult.userPub || "").slice(0, 16)}`;
|
|
330
|
+
authMethod = "zkproof";
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
throw new Error("ZK-Proof not supported with QuickStart");
|
|
334
|
+
}
|
|
248
335
|
break;
|
|
249
336
|
default:
|
|
250
337
|
throw new Error("Unsupported signup method");
|
|
251
338
|
}
|
|
252
339
|
if (result.success) {
|
|
253
|
-
|
|
340
|
+
let userPub = result.userPub || "";
|
|
341
|
+
if (!userPub && isShogunCore(core)) {
|
|
342
|
+
userPub = ((_b = (_a = core.gun.user()) === null || _a === void 0 ? void 0 : _a.is) === null || _b === void 0 ? void 0 : _b.pub) || "";
|
|
343
|
+
}
|
|
254
344
|
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
255
345
|
setIsLoggedIn(true);
|
|
256
346
|
setUserPub(userPub);
|
|
@@ -274,13 +364,18 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
274
364
|
};
|
|
275
365
|
// Logout
|
|
276
366
|
const logout = () => {
|
|
277
|
-
core
|
|
367
|
+
if (isShogunCore(core)) {
|
|
368
|
+
core.logout();
|
|
369
|
+
}
|
|
370
|
+
else if (isQuickStart(core)) {
|
|
371
|
+
// QuickStart doesn't have built-in logout, so we clear session storage
|
|
372
|
+
sessionStorage.removeItem("gun/pair");
|
|
373
|
+
sessionStorage.removeItem("gun/session");
|
|
374
|
+
sessionStorage.removeItem("pair");
|
|
375
|
+
}
|
|
278
376
|
setIsLoggedIn(false);
|
|
279
377
|
setUserPub(null);
|
|
280
378
|
setUsername(null);
|
|
281
|
-
sessionStorage.removeItem("gun/pair");
|
|
282
|
-
sessionStorage.removeItem("gun/session");
|
|
283
|
-
sessionStorage.removeItem("pair");
|
|
284
379
|
};
|
|
285
380
|
// Implementazione del metodo setProvider
|
|
286
381
|
const setProvider = (provider) => {
|
|
@@ -317,10 +412,24 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
317
412
|
}
|
|
318
413
|
};
|
|
319
414
|
const hasPlugin = (name) => {
|
|
320
|
-
|
|
415
|
+
if (isShogunCore(core)) {
|
|
416
|
+
return core.hasPlugin(name);
|
|
417
|
+
}
|
|
418
|
+
else if (isQuickStart(core)) {
|
|
419
|
+
// QuickStart doesn't have plugins
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
321
423
|
};
|
|
322
424
|
const getPlugin = (name) => {
|
|
323
|
-
|
|
425
|
+
if (isShogunCore(core)) {
|
|
426
|
+
return core.getPlugin(name);
|
|
427
|
+
}
|
|
428
|
+
else if (isQuickStart(core)) {
|
|
429
|
+
// QuickStart doesn't have plugins
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
return undefined;
|
|
324
433
|
};
|
|
325
434
|
// Export Gun pair functionality
|
|
326
435
|
const exportGunPair = async (password) => {
|
|
@@ -406,33 +515,75 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
406
515
|
setProvider,
|
|
407
516
|
gunPlugin,
|
|
408
517
|
put: async (path, data) => {
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
518
|
+
if (isShogunCore(core)) {
|
|
519
|
+
if (!core.gun)
|
|
520
|
+
throw new Error('Gun instance not available');
|
|
521
|
+
return new Promise((resolve, reject) => {
|
|
522
|
+
core.gun.get(path).put(data, (ack) => {
|
|
523
|
+
if (ack.err)
|
|
524
|
+
reject(new Error(ack.err));
|
|
525
|
+
else
|
|
526
|
+
resolve();
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
else if (isQuickStart(core)) {
|
|
531
|
+
if (!core.database.gun)
|
|
532
|
+
throw new Error('Gun instance not available');
|
|
533
|
+
return new Promise((resolve, reject) => {
|
|
534
|
+
core.database.gun.get(path).put(data, (ack) => {
|
|
535
|
+
if (ack.err)
|
|
536
|
+
reject(new Error(ack.err));
|
|
537
|
+
else
|
|
538
|
+
resolve();
|
|
539
|
+
});
|
|
417
540
|
});
|
|
418
|
-
}
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
throw new Error('Core not available');
|
|
544
|
+
}
|
|
419
545
|
},
|
|
420
546
|
get: (path) => {
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
547
|
+
if (isShogunCore(core)) {
|
|
548
|
+
if (!core.gun)
|
|
549
|
+
return null;
|
|
550
|
+
return core.gun.get(path);
|
|
551
|
+
}
|
|
552
|
+
else if (isQuickStart(core)) {
|
|
553
|
+
if (!core.database.gun)
|
|
554
|
+
return null;
|
|
555
|
+
return core.database.gun.get(path);
|
|
556
|
+
}
|
|
557
|
+
return null;
|
|
424
558
|
},
|
|
425
559
|
remove: async (path) => {
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
560
|
+
if (isShogunCore(core)) {
|
|
561
|
+
if (!core.gun)
|
|
562
|
+
throw new Error('Gun instance not available');
|
|
563
|
+
return new Promise((resolve, reject) => {
|
|
564
|
+
core.gun.get(path).put(null, (ack) => {
|
|
565
|
+
if (ack.err)
|
|
566
|
+
reject(new Error(ack.err));
|
|
567
|
+
else
|
|
568
|
+
resolve();
|
|
569
|
+
});
|
|
434
570
|
});
|
|
435
|
-
}
|
|
571
|
+
}
|
|
572
|
+
else if (isQuickStart(core)) {
|
|
573
|
+
if (!core.database.gun)
|
|
574
|
+
throw new Error('Gun instance not available');
|
|
575
|
+
return new Promise((resolve, reject) => {
|
|
576
|
+
core.database.gun.get(path).put(null, (ack) => {
|
|
577
|
+
if (ack.err)
|
|
578
|
+
reject(new Error(ack.err));
|
|
579
|
+
else
|
|
580
|
+
resolve();
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
throw new Error('Core not available');
|
|
586
|
+
}
|
|
436
587
|
},
|
|
437
588
|
}), [
|
|
438
589
|
core,
|
|
@@ -499,7 +650,7 @@ const ExportIcon = () => (React.createElement("svg", { xmlns: "http://www.w3.org
|
|
|
499
650
|
// Component for Shogun login button
|
|
500
651
|
export const ShogunButton = (() => {
|
|
501
652
|
const Button = () => {
|
|
502
|
-
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, } = useShogun();
|
|
653
|
+
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin, } = useShogun();
|
|
503
654
|
// Form states
|
|
504
655
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
505
656
|
const [formUsername, setFormUsername] = useState("");
|
|
@@ -602,7 +753,7 @@ export const ShogunButton = (() => {
|
|
|
602
753
|
if (formMode === "signup") {
|
|
603
754
|
const result = await signUp("password", formUsername, formPassword, formPasswordConfirm);
|
|
604
755
|
if (result && result.success) {
|
|
605
|
-
if (core
|
|
756
|
+
if (isShogunCore(core) && core.db) {
|
|
606
757
|
try {
|
|
607
758
|
const res = await core.db.setPasswordHintWithSecurity(formUsername, formPassword, formHint, [formSecurityQuestion], [formSecurityAnswer]);
|
|
608
759
|
if (!(res === null || res === void 0 ? void 0 : res.success)) {
|
|
@@ -633,14 +784,14 @@ export const ShogunButton = (() => {
|
|
|
633
784
|
}
|
|
634
785
|
};
|
|
635
786
|
const handleWebAuthnAuth = () => {
|
|
636
|
-
if (!
|
|
787
|
+
if (!hasPlugin("webauthn")) {
|
|
637
788
|
setError("WebAuthn is not supported in your browser");
|
|
638
789
|
return;
|
|
639
790
|
}
|
|
640
791
|
setAuthView("webauthn-username");
|
|
641
792
|
};
|
|
642
793
|
const handleZkProofAuth = () => {
|
|
643
|
-
if (!
|
|
794
|
+
if (!hasPlugin("zkproof")) {
|
|
644
795
|
setError("ZK-Proof plugin not available");
|
|
645
796
|
return;
|
|
646
797
|
}
|
|
@@ -694,18 +845,20 @@ export const ShogunButton = (() => {
|
|
|
694
845
|
setError("");
|
|
695
846
|
setLoading(true);
|
|
696
847
|
try {
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
848
|
+
if (isShogunCore(core) && core.db) {
|
|
849
|
+
const result = await core.db.forgotPassword(formUsername, [
|
|
850
|
+
formSecurityAnswer,
|
|
851
|
+
]);
|
|
852
|
+
if (result.success && result.hint) {
|
|
853
|
+
setRecoveredHint(result.hint);
|
|
854
|
+
setAuthView("showHint");
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
setError(result.error || "Could not recover hint.");
|
|
858
|
+
}
|
|
706
859
|
}
|
|
707
860
|
else {
|
|
708
|
-
setError(
|
|
861
|
+
setError("Password recovery not supported with QuickStart");
|
|
709
862
|
}
|
|
710
863
|
}
|
|
711
864
|
catch (e) {
|
|
@@ -796,23 +949,23 @@ export const ShogunButton = (() => {
|
|
|
796
949
|
};
|
|
797
950
|
// Add buttons for both login and signup for alternative auth methods
|
|
798
951
|
const renderAuthOptions = () => (React.createElement("div", { className: "shogun-auth-options" },
|
|
799
|
-
options.showMetamask !== false &&
|
|
952
|
+
options.showMetamask !== false && hasPlugin("web3") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
800
953
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("web3"), disabled: loading },
|
|
801
954
|
React.createElement(WalletIcon, null),
|
|
802
955
|
formMode === "login"
|
|
803
956
|
? "Login with MetaMask"
|
|
804
957
|
: "Signup with MetaMask"))),
|
|
805
|
-
options.showWebauthn !== false &&
|
|
958
|
+
options.showWebauthn !== false && hasPlugin("webauthn") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
806
959
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: handleWebAuthnAuth, disabled: loading },
|
|
807
960
|
React.createElement(WebAuthnIcon, null),
|
|
808
961
|
formMode === "login"
|
|
809
962
|
? "Login with WebAuthn"
|
|
810
963
|
: "Signup with WebAuthn"))),
|
|
811
|
-
options.showNostr !== false &&
|
|
964
|
+
options.showNostr !== false && hasPlugin("nostr") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
812
965
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("nostr"), disabled: loading },
|
|
813
966
|
React.createElement(NostrIcon, null),
|
|
814
967
|
formMode === "login" ? "Login with Nostr" : "Signup with Nostr"))),
|
|
815
|
-
options.showZkProof !== false &&
|
|
968
|
+
options.showZkProof !== false && hasPlugin("zkproof") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
816
969
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: handleZkProofAuth, disabled: loading },
|
|
817
970
|
React.createElement(ZkProofIcon, null),
|
|
818
971
|
formMode === "login"
|