shogun-button-react 4.3.6 → 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 -697
- 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 +286 -131
- package/dist/connector.js +50 -27
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +0 -2
- package/dist/interfaces/connector-options.d.ts +5 -0
- 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,9 +252,18 @@ 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...`);
|
|
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
|
+
}
|
|
266
|
+
console.log(`[DEBUG] ShogunButton: core.signUp completed successfully`);
|
|
198
267
|
console.log(`[DEBUG] ShogunButton: core.signUp result:`, result);
|
|
199
268
|
}
|
|
200
269
|
catch (error) {
|
|
@@ -204,51 +273,74 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
204
273
|
break;
|
|
205
274
|
case "webauthn":
|
|
206
275
|
username = args[0];
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
}
|
|
211
285
|
break;
|
|
212
286
|
case "web3":
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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");
|
|
219
300
|
}
|
|
220
|
-
username = connectionResult.address;
|
|
221
|
-
result = await web3.signUp(connectionResult.address);
|
|
222
301
|
break;
|
|
223
302
|
case "nostr":
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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");
|
|
230
319
|
}
|
|
231
|
-
const pubkey = nostrResult.address;
|
|
232
|
-
if (!pubkey)
|
|
233
|
-
throw new Error("Nessuna chiave pubblica ottenuta");
|
|
234
|
-
username = pubkey;
|
|
235
|
-
result = await nostr.signUp(pubkey);
|
|
236
320
|
break;
|
|
237
321
|
case "zkproof":
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
+
}
|
|
246
335
|
break;
|
|
247
336
|
default:
|
|
248
337
|
throw new Error("Unsupported signup method");
|
|
249
338
|
}
|
|
250
339
|
if (result.success) {
|
|
251
|
-
|
|
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
|
+
}
|
|
252
344
|
const displayName = result.alias || username || userPub.slice(0, 8) + "...";
|
|
253
345
|
setIsLoggedIn(true);
|
|
254
346
|
setUserPub(userPub);
|
|
@@ -272,13 +364,18 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
272
364
|
};
|
|
273
365
|
// Logout
|
|
274
366
|
const logout = () => {
|
|
275
|
-
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
|
+
}
|
|
276
376
|
setIsLoggedIn(false);
|
|
277
377
|
setUserPub(null);
|
|
278
378
|
setUsername(null);
|
|
279
|
-
sessionStorage.removeItem("gun/pair");
|
|
280
|
-
sessionStorage.removeItem("gun/session");
|
|
281
|
-
sessionStorage.removeItem("pair");
|
|
282
379
|
};
|
|
283
380
|
// Implementazione del metodo setProvider
|
|
284
381
|
const setProvider = (provider) => {
|
|
@@ -315,10 +412,24 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
315
412
|
}
|
|
316
413
|
};
|
|
317
414
|
const hasPlugin = (name) => {
|
|
318
|
-
|
|
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;
|
|
319
423
|
};
|
|
320
424
|
const getPlugin = (name) => {
|
|
321
|
-
|
|
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;
|
|
322
433
|
};
|
|
323
434
|
// Export Gun pair functionality
|
|
324
435
|
const exportGunPair = async (password) => {
|
|
@@ -404,33 +515,75 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
404
515
|
setProvider,
|
|
405
516
|
gunPlugin,
|
|
406
517
|
put: async (path, data) => {
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
+
});
|
|
415
540
|
});
|
|
416
|
-
}
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
throw new Error('Core not available');
|
|
544
|
+
}
|
|
417
545
|
},
|
|
418
546
|
get: (path) => {
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
|
|
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;
|
|
422
558
|
},
|
|
423
559
|
remove: async (path) => {
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
+
});
|
|
432
570
|
});
|
|
433
|
-
}
|
|
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
|
+
}
|
|
434
587
|
},
|
|
435
588
|
}), [
|
|
436
589
|
core,
|
|
@@ -497,7 +650,7 @@ const ExportIcon = () => (React.createElement("svg", { xmlns: "http://www.w3.org
|
|
|
497
650
|
// Component for Shogun login button
|
|
498
651
|
export const ShogunButton = (() => {
|
|
499
652
|
const Button = () => {
|
|
500
|
-
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, } = useShogun();
|
|
653
|
+
const { isLoggedIn, username, logout, login, signUp, core, options, exportGunPair, importGunPair, hasPlugin, } = useShogun();
|
|
501
654
|
// Form states
|
|
502
655
|
const [modalIsOpen, setModalIsOpen] = useState(false);
|
|
503
656
|
const [formUsername, setFormUsername] = useState("");
|
|
@@ -600,7 +753,7 @@ export const ShogunButton = (() => {
|
|
|
600
753
|
if (formMode === "signup") {
|
|
601
754
|
const result = await signUp("password", formUsername, formPassword, formPasswordConfirm);
|
|
602
755
|
if (result && result.success) {
|
|
603
|
-
if (core
|
|
756
|
+
if (isShogunCore(core) && core.db) {
|
|
604
757
|
try {
|
|
605
758
|
const res = await core.db.setPasswordHintWithSecurity(formUsername, formPassword, formHint, [formSecurityQuestion], [formSecurityAnswer]);
|
|
606
759
|
if (!(res === null || res === void 0 ? void 0 : res.success)) {
|
|
@@ -631,14 +784,14 @@ export const ShogunButton = (() => {
|
|
|
631
784
|
}
|
|
632
785
|
};
|
|
633
786
|
const handleWebAuthnAuth = () => {
|
|
634
|
-
if (!
|
|
787
|
+
if (!hasPlugin("webauthn")) {
|
|
635
788
|
setError("WebAuthn is not supported in your browser");
|
|
636
789
|
return;
|
|
637
790
|
}
|
|
638
791
|
setAuthView("webauthn-username");
|
|
639
792
|
};
|
|
640
793
|
const handleZkProofAuth = () => {
|
|
641
|
-
if (!
|
|
794
|
+
if (!hasPlugin("zkproof")) {
|
|
642
795
|
setError("ZK-Proof plugin not available");
|
|
643
796
|
return;
|
|
644
797
|
}
|
|
@@ -692,18 +845,20 @@ export const ShogunButton = (() => {
|
|
|
692
845
|
setError("");
|
|
693
846
|
setLoading(true);
|
|
694
847
|
try {
|
|
695
|
-
if (
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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
|
+
}
|
|
704
859
|
}
|
|
705
860
|
else {
|
|
706
|
-
setError(
|
|
861
|
+
setError("Password recovery not supported with QuickStart");
|
|
707
862
|
}
|
|
708
863
|
}
|
|
709
864
|
catch (e) {
|
|
@@ -794,23 +949,23 @@ export const ShogunButton = (() => {
|
|
|
794
949
|
};
|
|
795
950
|
// Add buttons for both login and signup for alternative auth methods
|
|
796
951
|
const renderAuthOptions = () => (React.createElement("div", { className: "shogun-auth-options" },
|
|
797
|
-
options.showMetamask !== false &&
|
|
952
|
+
options.showMetamask !== false && hasPlugin("web3") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
798
953
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("web3"), disabled: loading },
|
|
799
954
|
React.createElement(WalletIcon, null),
|
|
800
955
|
formMode === "login"
|
|
801
956
|
? "Login with MetaMask"
|
|
802
957
|
: "Signup with MetaMask"))),
|
|
803
|
-
options.showWebauthn !== false &&
|
|
958
|
+
options.showWebauthn !== false && hasPlugin("webauthn") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
804
959
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: handleWebAuthnAuth, disabled: loading },
|
|
805
960
|
React.createElement(WebAuthnIcon, null),
|
|
806
961
|
formMode === "login"
|
|
807
962
|
? "Login with WebAuthn"
|
|
808
963
|
: "Signup with WebAuthn"))),
|
|
809
|
-
options.showNostr !== false &&
|
|
964
|
+
options.showNostr !== false && hasPlugin("nostr") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
810
965
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: () => handleAuth("nostr"), disabled: loading },
|
|
811
966
|
React.createElement(NostrIcon, null),
|
|
812
967
|
formMode === "login" ? "Login with Nostr" : "Signup with Nostr"))),
|
|
813
|
-
options.showZkProof !== false &&
|
|
968
|
+
options.showZkProof !== false && hasPlugin("zkproof") && (React.createElement("div", { className: "shogun-auth-option-group" },
|
|
814
969
|
React.createElement("button", { type: "button", className: "shogun-auth-option-button", onClick: handleZkProofAuth, disabled: loading },
|
|
815
970
|
React.createElement(ZkProofIcon, null),
|
|
816
971
|
formMode === "login"
|