shogun-core 0.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.
Files changed (60) hide show
  1. package/README.md +71 -0
  2. package/dist/auth/credentialAuth.js +154 -0
  3. package/dist/auth/metamaskAuth.js +264 -0
  4. package/dist/auth/webauthnAuth.js +267 -0
  5. package/dist/config.js +39 -0
  6. package/dist/connector/metamask.js +262 -0
  7. package/dist/events.js +12 -0
  8. package/dist/gun/auth.js +523 -0
  9. package/dist/gun/errors.js +66 -0
  10. package/dist/gun/gun.js +331 -0
  11. package/dist/index.js +440 -0
  12. package/dist/mom/MOMClient.js +1253 -0
  13. package/dist/stealth/stealth.js +289 -0
  14. package/dist/storage/storage.js +93 -0
  15. package/dist/types/auth/credentialAuth.d.ts +56 -0
  16. package/dist/types/auth/metamaskAuth.d.ts +74 -0
  17. package/dist/types/auth/webauthnAuth.d.ts +83 -0
  18. package/dist/types/auth.js +1 -0
  19. package/dist/types/config.d.ts +39 -0
  20. package/dist/types/connector/metamask.d.ts +112 -0
  21. package/dist/types/events.d.ts +27 -0
  22. package/dist/types/gun/auth.d.ts +219 -0
  23. package/dist/types/gun/errors.d.ts +42 -0
  24. package/dist/types/gun/gun.d.ts +124 -0
  25. package/dist/types/gun.js +4 -0
  26. package/dist/types/index.d.ts +173 -0
  27. package/dist/types/mom/MOMClient.d.ts +217 -0
  28. package/dist/types/mom.js +29 -0
  29. package/dist/types/shogun.js +1 -0
  30. package/dist/types/stealth/stealth.d.ts +67 -0
  31. package/dist/types/storage/storage.d.ts +11 -0
  32. package/dist/types/token.js +1 -0
  33. package/dist/types/types/auth.d.ts +47 -0
  34. package/dist/types/types/gun.d.ts +73 -0
  35. package/dist/types/types/mom.d.ts +147 -0
  36. package/dist/types/types/shogun.d.ts +90 -0
  37. package/dist/types/types/token.d.ts +12 -0
  38. package/dist/types/utils/eventEmitter.d.ts +9 -0
  39. package/dist/types/utils/logger.d.ts +24 -0
  40. package/dist/types/utils/storageMock.d.ts +12 -0
  41. package/dist/types/utils/utility.d.ts +20 -0
  42. package/dist/types/utils/wait.d.ts +24 -0
  43. package/dist/types/wallet/gunWallet.d.ts +14 -0
  44. package/dist/types/wallet/hdWallet.d.ts +154 -0
  45. package/dist/types/wallet/walletManager-old.d.ts +70 -0
  46. package/dist/types/wallet/walletManager.d.ts +188 -0
  47. package/dist/types/webauthn/webauthn-gun.d.ts +1 -0
  48. package/dist/types/webauthn/webauthn.d.ts +52 -0
  49. package/dist/utils/eventEmitter.js +29 -0
  50. package/dist/utils/logger.js +39 -0
  51. package/dist/utils/storageMock.js +27 -0
  52. package/dist/utils/utility.js +32 -0
  53. package/dist/utils/wait.js +78 -0
  54. package/dist/wallet/gunWallet.js +14 -0
  55. package/dist/wallet/hdWallet.js +619 -0
  56. package/dist/wallet/walletManager-old.js +473 -0
  57. package/dist/wallet/walletManager.js +1226 -0
  58. package/dist/webauthn/webauthn-gun.js +115 -0
  59. package/dist/webauthn/webauthn.js +313 -0
  60. package/package.json +48 -0
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Gestisce la logica stealth usando Gun e SEA
3
+ */
4
+ import { ethers } from 'ethers';
5
+ class Stealth {
6
+ constructor() {
7
+ this.lastEphemeralKeyPair = null;
8
+ this.lastMethodUsed = "unknown";
9
+ this.STEALTH_DATA_TABLE = "Stealth";
10
+ }
11
+ /**
12
+ * Rimuove il tilde (~) iniziale dalla chiave pubblica se presente
13
+ */
14
+ formatPublicKey(publicKey) {
15
+ if (!publicKey) {
16
+ return null;
17
+ }
18
+ const trimmedKey = publicKey.trim();
19
+ if (!trimmedKey) {
20
+ return null;
21
+ }
22
+ if (!/^[~]?[\w+/=\-_.]+$/.test(trimmedKey)) {
23
+ return null;
24
+ }
25
+ return trimmedKey.startsWith("~") ? trimmedKey.slice(1) : trimmedKey;
26
+ }
27
+ /**
28
+ * Crea un nuovo account stealth
29
+ */
30
+ async createAccount() {
31
+ try {
32
+ // Genera una nuova coppia di chiavi
33
+ const keyPair = await Gun.SEA.pair();
34
+ if (!keyPair || !keyPair.pub || !keyPair.priv || !keyPair.epub || !keyPair.epriv) {
35
+ throw new Error("Failed to generate stealth key pair");
36
+ }
37
+ return {
38
+ pub: keyPair.pub,
39
+ priv: keyPair.priv,
40
+ epub: keyPair.epub,
41
+ epriv: keyPair.epriv
42
+ };
43
+ }
44
+ catch (error) {
45
+ console.error("Error creating stealth account:", error);
46
+ throw error;
47
+ }
48
+ }
49
+ /**
50
+ * Genera un indirizzo stealth per la chiave pubblica del destinatario
51
+ */
52
+ async generateStealthAddress(recipientPublicKey) {
53
+ if (!recipientPublicKey) {
54
+ throw new Error("Invalid keys: missing or invalid parameters");
55
+ }
56
+ // Prima creiamo le chiavi stealth se non esistono
57
+ const stealthKeys = await this.createAccount();
58
+ if (!stealthKeys) {
59
+ throw new Error("Failed to create stealth keys");
60
+ }
61
+ console.log("Generazione indirizzo stealth con chiavi:", {
62
+ userPub: stealthKeys.pub,
63
+ userEpub: stealthKeys.epub,
64
+ recipientPub: recipientPublicKey
65
+ });
66
+ return new Promise((resolve, reject) => {
67
+ // Genera una coppia di chiavi effimere
68
+ Gun.SEA.pair((ephemeralKeyPair) => {
69
+ if (!ephemeralKeyPair?.epub || !ephemeralKeyPair?.epriv) {
70
+ reject(new Error("Invalid ephemeral keys"));
71
+ return;
72
+ }
73
+ console.log("Chiavi effimere generate:", ephemeralKeyPair);
74
+ // Memorizza l'intero pair per debug
75
+ this.lastEphemeralKeyPair = ephemeralKeyPair;
76
+ // MODIFICA CRUCIALE: Usiamo l'interfaccia definita
77
+ const stealthData = {
78
+ recipientPublicKey,
79
+ ephemeralKeyPair: ephemeralKeyPair,
80
+ timestamp: Date.now()
81
+ };
82
+ // Usa questo formato specifico per il parametro di SEA.secret
83
+ const keyForSecret = {
84
+ epub: ephemeralKeyPair.epub,
85
+ epriv: ephemeralKeyPair.epriv
86
+ };
87
+ console.log("Formato chiave per segreto (generazione):", JSON.stringify(keyForSecret));
88
+ Gun.SEA.secret(recipientPublicKey, keyForSecret, async (sharedSecret) => {
89
+ console.log("Segreto condiviso generato correttamente con le chiavi del destinatario");
90
+ console.log("Formato di input usato:", {
91
+ recipientPublicKey,
92
+ ephemeralKeyObject: keyForSecret
93
+ });
94
+ try {
95
+ // Genera l'indirizzo stealth usando il segreto condiviso
96
+ const stealthPrivateKey = ethers.keccak256(ethers.toUtf8Bytes(sharedSecret));
97
+ const stealthWallet = new ethers.Wallet(stealthPrivateKey);
98
+ console.log("Indirizzo stealth generato:", {
99
+ address: stealthWallet.address,
100
+ ephemeralPubKey: ephemeralKeyPair.epub,
101
+ recipientPublicKey
102
+ });
103
+ // Salva il metodo utilizzato e il segreto condiviso
104
+ this.lastMethodUsed = "standard";
105
+ stealthData.method = "standard";
106
+ stealthData.sharedSecret = sharedSecret;
107
+ // Salva i dati nella memoria locale per consentire l'apertura
108
+ this.saveStealthHistory(stealthWallet.address, stealthData);
109
+ resolve({
110
+ stealthAddress: stealthWallet.address,
111
+ ephemeralPublicKey: ephemeralKeyPair.epub,
112
+ recipientPublicKey
113
+ });
114
+ }
115
+ catch (error) {
116
+ reject(new Error(`Error creating stealth address: ${error instanceof Error ? error.message : "unknown error"}`));
117
+ }
118
+ });
119
+ });
120
+ });
121
+ }
122
+ /**
123
+ * Apre un indirizzo stealth derivando la chiave privata
124
+ */
125
+ async openStealthAddress(stealthAddress, ephemeralPublicKey, pair) {
126
+ console.log(`Tentativo di apertura dell'indirizzo stealth ${stealthAddress}`);
127
+ // Prima controlla se abbiamo i dati salvati in locale
128
+ try {
129
+ const stealthHistory = localStorage.getItem('stealthHistory') || '{}';
130
+ const history = JSON.parse(stealthHistory);
131
+ console.log(`Controllo se esistono dati per l'indirizzo ${stealthAddress} in localStorage`);
132
+ if (history[stealthAddress]) {
133
+ console.log("Trovati dati stealth salvati localmente:", history[stealthAddress]);
134
+ const data = history[stealthAddress];
135
+ // Se abbiamo il segreto condiviso, possiamo derivare direttamente il wallet
136
+ if (data.sharedSecret) {
137
+ console.log("Derivazione diretta dal segreto condiviso salvato");
138
+ const stealthPrivateKey = ethers.keccak256(ethers.toUtf8Bytes(data.sharedSecret));
139
+ return new ethers.Wallet(stealthPrivateKey);
140
+ }
141
+ // Se abbiamo il metodo e le chiavi effimere complete, proviamo a rigenerare il segreto
142
+ if (data.method && data.ephemeralKeyPair) {
143
+ console.log("Tentativo di rigenerazione del segreto con il metodo:", data.method);
144
+ if (data.method === "standard") {
145
+ // Usa il formato specifico che abbiamo usato durante la generazione
146
+ const keyForSecret = {
147
+ epub: data.ephemeralKeyPair.epub,
148
+ epriv: data.ephemeralKeyPair.epriv
149
+ };
150
+ console.log("Rigenerazione con formato esplicito:", JSON.stringify(keyForSecret));
151
+ return new Promise((resolve, reject) => {
152
+ Gun.SEA.secret(data.recipientPublicKey, keyForSecret, async (secret) => {
153
+ if (!secret) {
154
+ return reject(new Error("Impossibile rigenerare il segreto condiviso"));
155
+ }
156
+ try {
157
+ const stealthPrivateKey = ethers.keccak256(ethers.toUtf8Bytes(secret));
158
+ const wallet = new ethers.Wallet(stealthPrivateKey);
159
+ // Verifica che il wallet generato corrisponda all'indirizzo
160
+ if (wallet.address.toLowerCase() === stealthAddress.toLowerCase()) {
161
+ console.log("Rigenerazione riuscita! Indirizzo corrispondente:", wallet.address);
162
+ return resolve(wallet);
163
+ }
164
+ else {
165
+ console.log("Indirizzo generato non corrispondente:", wallet.address);
166
+ // Continua con i metodi standard
167
+ }
168
+ }
169
+ catch (e) {
170
+ console.error("Errore durante la derivazione:", e);
171
+ // Continua con i metodi standard
172
+ }
173
+ });
174
+ });
175
+ }
176
+ }
177
+ }
178
+ else {
179
+ console.log("Nessun dato stealth trovato in localStorage per questo indirizzo");
180
+ }
181
+ }
182
+ catch (e) {
183
+ console.log("Errore nel recupero dei dati da localStorage:", e);
184
+ }
185
+ // Se non abbiamo dati salvati, procedi con il metodo normale
186
+ if (!stealthAddress || !ephemeralPublicKey) {
187
+ throw new Error("Missing parameters: stealthAddress or ephemeralPublicKey");
188
+ }
189
+ // Recupera le chiavi stealth dell'utente
190
+ let keys = pair;
191
+ console.log("Apertura indirizzo stealth con chiavi recuperate:", {
192
+ stealthAddress,
193
+ ephemeralPublicKey,
194
+ userKeysFound: !!keys
195
+ });
196
+ return new Promise((resolve, reject) => {
197
+ // Prova tutte le possibili combinazioni di parametri per SEA.secret
198
+ const attempts = [
199
+ // Tentativo 1: Metodo standard - ephemeral keys first
200
+ () => {
201
+ console.log("Tentativo 1: Metodo standard con chiavi effimere");
202
+ return new Promise((res) => {
203
+ Gun.SEA.secret(ephemeralPublicKey, keys, async (secret) => {
204
+ try {
205
+ if (!secret) {
206
+ return res(null);
207
+ }
208
+ const wallet = this.deriveWalletFromSecret(secret);
209
+ if (wallet.address.toLowerCase() === stealthAddress.toLowerCase()) {
210
+ return res(wallet);
211
+ }
212
+ return res(null);
213
+ }
214
+ catch (e) {
215
+ return res(null);
216
+ }
217
+ });
218
+ });
219
+ }
220
+ ];
221
+ // Funzione helper per derivare il wallet dal secret
222
+ this.deriveWalletFromSecret = (secret) => {
223
+ const stealthPrivateKey = ethers.keccak256(ethers.toUtf8Bytes(secret));
224
+ return new ethers.Wallet(stealthPrivateKey);
225
+ };
226
+ // Esegui tutti i tentativi in sequenza
227
+ const tryNextAttempt = async (index = 0) => {
228
+ if (index >= attempts.length) {
229
+ return reject(new Error("Tutti i metodi di derivazione dell'indirizzo stealth hanno fallito"));
230
+ }
231
+ const wallet = await attempts[index]();
232
+ if (wallet) {
233
+ console.log(`Metodo ${index + 1} ha funzionato!`);
234
+ return resolve(wallet);
235
+ }
236
+ tryNextAttempt(index + 1);
237
+ };
238
+ tryNextAttempt();
239
+ });
240
+ }
241
+ /**
242
+ * Ottiene la chiave pubblica da un indirizzo
243
+ */
244
+ async getPublicKey(publicKey) {
245
+ // Formatta la chiave pubblica
246
+ return this.formatPublicKey(publicKey);
247
+ }
248
+ /**
249
+ * Salva le chiavi stealth nel profilo utente
250
+ * @returns Le chiavi stealth da salvare
251
+ */
252
+ prepareStealthKeysForSaving(stealthKeyPair) {
253
+ if (!stealthKeyPair?.pub || !stealthKeyPair?.priv || !stealthKeyPair?.epub || !stealthKeyPair?.epriv) {
254
+ throw new Error("Invalid stealth keys: missing or incomplete parameters");
255
+ }
256
+ return stealthKeyPair;
257
+ }
258
+ /**
259
+ * Deriva un wallet dal segreto condiviso
260
+ */
261
+ deriveWalletFromSecret(secret) {
262
+ const stealthPrivateKey = ethers.keccak256(ethers.toUtf8Bytes(secret));
263
+ return new ethers.Wallet(stealthPrivateKey);
264
+ }
265
+ /**
266
+ * Salva i dati stealth nella localStorage
267
+ */
268
+ saveStealthHistory(address, data) {
269
+ // Salva nella localStorage
270
+ try {
271
+ const stealthHistory = localStorage.getItem('stealthHistory') || '{}';
272
+ const history = JSON.parse(stealthHistory);
273
+ history[address] = data;
274
+ localStorage.setItem('stealthHistory', JSON.stringify(history));
275
+ console.log(`Dati stealth salvati per l'indirizzo ${address}`);
276
+ }
277
+ catch (e) {
278
+ console.error("Errore nel salvataggio dei dati stealth:", e);
279
+ }
280
+ }
281
+ }
282
+ // Rendi disponibile globalmente
283
+ if (typeof window !== 'undefined') {
284
+ window.Stealth = Stealth;
285
+ }
286
+ else if (typeof global !== 'undefined') {
287
+ global.Stealth = Stealth;
288
+ }
289
+ export { Stealth };
@@ -0,0 +1,93 @@
1
+ // Implementazione della Storage basata su StorageMock
2
+ export class Storage {
3
+ constructor() {
4
+ this.store = new Map();
5
+ // Se in ambiente browser, tenta di caricare i dati da localStorage
6
+ if (typeof localStorage !== "undefined") {
7
+ try {
8
+ const storedPair = localStorage.getItem("shogun_keypair");
9
+ if (storedPair) {
10
+ this.store.set("keypair", JSON.parse(storedPair));
11
+ }
12
+ }
13
+ catch (error) {
14
+ console.error("Errore nel recuperare i dati da localStorage:", error);
15
+ }
16
+ }
17
+ }
18
+ async getPair() {
19
+ return this.getPairSync();
20
+ }
21
+ getPairSync() {
22
+ return this.store.get("keypair") || null;
23
+ }
24
+ async setPair(pair) {
25
+ this.store.set("keypair", pair);
26
+ // Se in ambiente browser, salva anche nel localStorage
27
+ if (typeof localStorage !== "undefined") {
28
+ try {
29
+ localStorage.setItem("shogun_keypair", JSON.stringify(pair));
30
+ }
31
+ catch (error) {
32
+ console.error("Errore nel salvare i dati nel localStorage:", error);
33
+ }
34
+ }
35
+ }
36
+ clearAll() {
37
+ this.store.clear();
38
+ // Se in ambiente browser, pulisci anche localStorage
39
+ if (typeof localStorage !== "undefined") {
40
+ try {
41
+ localStorage.removeItem("shogun_keypair");
42
+ }
43
+ catch (error) {
44
+ console.error("Errore nel rimuovere i dati dal localStorage:", error);
45
+ }
46
+ }
47
+ }
48
+ // Metodi per compatibilità con l'interfaccia Storage standard
49
+ getItem(key) {
50
+ const value = this.store.get(key);
51
+ return value !== undefined ? JSON.stringify(value) : null;
52
+ }
53
+ setItem(key, value) {
54
+ try {
55
+ const parsedValue = JSON.parse(value);
56
+ this.store.set(key, parsedValue);
57
+ // Se in ambiente browser, salva anche nel localStorage
58
+ if (typeof localStorage !== "undefined") {
59
+ try {
60
+ localStorage.setItem(key, value);
61
+ }
62
+ catch (error) {
63
+ console.error(`Errore nel salvare ${key} nel localStorage:`, error);
64
+ }
65
+ }
66
+ }
67
+ catch (error) {
68
+ // Se non è JSON valido, salva come stringa
69
+ this.store.set(key, value);
70
+ // Se in ambiente browser, salva anche nel localStorage
71
+ if (typeof localStorage !== "undefined") {
72
+ try {
73
+ localStorage.setItem(key, value);
74
+ }
75
+ catch (error) {
76
+ console.error(`Errore nel salvare ${key} nel localStorage:`, error);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ removeItem(key) {
82
+ this.store.delete(key);
83
+ // Se in ambiente browser, rimuovi anche dal localStorage
84
+ if (typeof localStorage !== "undefined") {
85
+ try {
86
+ localStorage.removeItem(key);
87
+ }
88
+ catch (error) {
89
+ console.error(`Errore nel rimuovere ${key} dal localStorage:`, error);
90
+ }
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,56 @@
1
+ import { GunDB } from "../gun/gun";
2
+ import { Storage } from "../storage/storage";
3
+ import { AuthResult } from "../gun/auth";
4
+ /**
5
+ * Classe per l'autenticazione con username e password
6
+ * Livello più alto di astrazione per gestire l'autenticazione utente
7
+ */
8
+ export declare class UserAuth {
9
+ private gundb;
10
+ private gun;
11
+ private storage;
12
+ private auth;
13
+ constructor(gundb: GunDB, gun: any, storage: Storage);
14
+ /**
15
+ * Crea un risultato di autenticazione
16
+ * @param success - Indica se l'autenticazione è riuscita
17
+ * @param data - Dati aggiuntivi
18
+ * @returns Risultato dell'autenticazione
19
+ */
20
+ private createAuthResult;
21
+ /**
22
+ * Metodo principale per l'autenticazione dell'utente
23
+ * @param username - Nome utente
24
+ * @param password - Password
25
+ * @param options - Opzioni avanzate per il login
26
+ * @returns Risultato dell'autenticazione
27
+ */
28
+ login(username: string, password: string, options?: {
29
+ setUserpub?: (pub: string) => void;
30
+ setSignedIn?: (signedIn: boolean) => void;
31
+ timeout?: number;
32
+ attemptCleanup?: boolean;
33
+ retryCount?: number;
34
+ }): Promise<AuthResult>;
35
+ /**
36
+ * Metodo principale per la registrazione di un nuovo utente
37
+ * @param username - Nome utente
38
+ * @param password - Password
39
+ * @param passwordConfirmation - Conferma password
40
+ * @param options - Opzioni avanzate per la registrazione
41
+ * @returns Risultato della registrazione
42
+ */
43
+ register(username: string, password: string, passwordConfirmation: string, options?: {
44
+ setErrorMessage?: (message: string) => void;
45
+ setUserpub?: (pub: string) => void;
46
+ setSignedIn?: (signedIn: boolean) => void;
47
+ messages?: {
48
+ [key: string]: string;
49
+ };
50
+ forceResetUser?: boolean;
51
+ timeout?: number;
52
+ attemptCleanup?: boolean;
53
+ cleanupFirst?: boolean;
54
+ }): Promise<AuthResult>;
55
+ }
56
+ export declare const CredentialAuth: typeof UserAuth;
@@ -0,0 +1,74 @@
1
+ import { AuthResult } from "../gun/auth";
2
+ import { GunDB } from "../gun/gun";
3
+ import { Storage } from "../storage/storage";
4
+ import { MetaMask } from "../connector/metamask";
5
+ import { ethers } from "ethers";
6
+ /**
7
+ * Gestisce l'autenticazione con MetaMask
8
+ */
9
+ export declare class MetaMaskAuth {
10
+ private gun;
11
+ private gundb;
12
+ private storage;
13
+ private auth;
14
+ private metamask;
15
+ private signer;
16
+ constructor(gundb: GunDB, gun: any, storage: Storage, metamask: MetaMask);
17
+ /**
18
+ * Crea un oggetto AuthResult
19
+ * @param success - Se l'operazione è riuscita
20
+ * @param data - Dati aggiuntivi
21
+ * @returns AuthResult
22
+ */
23
+ private createAuthResult;
24
+ /**
25
+ * Normalizza un indirizzo Ethereum
26
+ * @param address - Indirizzo da normalizzare
27
+ * @returns Indirizzo normalizzato
28
+ */
29
+ private normalizeEthAddress;
30
+ /**
31
+ * Registra un utente con MetaMask
32
+ * @param address - Indirizzo Ethereum da MetaMask
33
+ * @returns Risultato dell'autenticazione
34
+ */
35
+ /**
36
+ * Ottiene il signer Ethereum
37
+ * @returns Signer Ethereum
38
+ */
39
+ getSigner(): ethers.Signer | null;
40
+ /**
41
+ * Gestisce il login con MetaMask
42
+ * @param address - Indirizzo Ethereum
43
+ * @returns Risultato del login
44
+ */
45
+ loginWithMetaMask(address: string): Promise<AuthResult>;
46
+ /**
47
+ * Registra un utente con credenziali MetaMask
48
+ * @param address - Indirizzo Ethereum
49
+ * @returns Risultato dell'autenticazione
50
+ */
51
+ private registerUserWithMetaMask;
52
+ /**
53
+ * Gestisce la registrazione con MetaMask
54
+ * @param address - Indirizzo Ethereum
55
+ * @returns Risultato della registrazione
56
+ */
57
+ signUpWithMetaMask(address: string): Promise<AuthResult>;
58
+ /**
59
+ * Ottiene le credenziali MetaMask salvate per un indirizzo
60
+ * @param address - Indirizzo Ethereum
61
+ * @returns Credenziali o null se non trovate
62
+ */
63
+ getMetaMaskCredentials(address: string): Promise<{
64
+ username: string;
65
+ password: string;
66
+ } | null>;
67
+ /**
68
+ * Autentica un utente con username e password
69
+ * @param username - Nome utente
70
+ * @param password - Password
71
+ * @returns Risultato dell'autenticazione
72
+ */
73
+ private authenticateWithCredentials;
74
+ }
@@ -0,0 +1,83 @@
1
+ import { GunDB } from "../gun/gun";
2
+ import { Storage } from "../storage/storage";
3
+ import { Webauthn } from "../webauthn/webauthn";
4
+ import { AuthResult } from "../types/shogun";
5
+ /**
6
+ * Classe che gestisce l'autenticazione con WebAuthn
7
+ */
8
+ export declare class WebAuthnAuth {
9
+ private gundb;
10
+ private gun;
11
+ private storage;
12
+ private webauthn;
13
+ private auth;
14
+ constructor(gundb: GunDB, gun: any, storage: Storage, webauthn: Webauthn);
15
+ /**
16
+ * Crea un risultato di autenticazione
17
+ * @param success - Indica se l'autenticazione è riuscita
18
+ * @param data - Dati aggiuntivi
19
+ * @returns Risultato dell'autenticazione
20
+ */
21
+ private createAuthResult;
22
+ /**
23
+ * Verifica se WebAuthn è supportato
24
+ * @returns true se WebAuthn è supportato, false altrimenti
25
+ */
26
+ isWebAuthnSupported(): boolean;
27
+ /**
28
+ * Effettua il login con WebAuthn
29
+ * @param username - Nome utente
30
+ * @returns Risultato del login
31
+ */
32
+ loginWithWebAuthn(username: string, credentialId: string, options?: {
33
+ setUserpub?: (pub: string) => void;
34
+ setSignedIn?: (signedIn: boolean) => void;
35
+ }): Promise<AuthResult>;
36
+ /**
37
+ * Registra un nuovo utente con WebAuthn
38
+ * @param username - Nome utente
39
+ * @returns Risultato della registrazione
40
+ */
41
+ registerWithWebAuthn(username: string, credentialId: string, options?: {
42
+ setErrorMessage?: (message: string) => void;
43
+ setUserpub?: (pub: string) => void;
44
+ setSignedIn?: (signedIn: boolean) => void;
45
+ }): Promise<AuthResult>;
46
+ /**
47
+ * Recupera le credenziali WebAuthn
48
+ * @param username - Nome utente
49
+ * @returns Credenziali WebAuthn o null se non trovate
50
+ */
51
+ private getWebAuthnCredentials;
52
+ /**
53
+ * Salva le credenziali WebAuthn
54
+ * @param username - Nome utente
55
+ * @param credentials - Credenziali WebAuthn
56
+ */
57
+ private saveWebAuthnCredentials;
58
+ /**
59
+ * Gestisce il login con WebAuthn
60
+ */
61
+ handleWebAuthnLogin(username: string, credentials: {
62
+ id: string;
63
+ rawId: string;
64
+ type: string;
65
+ response: any;
66
+ }, options?: {
67
+ setUserpub?: (pub: string) => void;
68
+ setSignedIn?: (signedIn: boolean) => void;
69
+ }): Promise<AuthResult>;
70
+ /**
71
+ * Gestisce la registrazione con WebAuthn
72
+ */
73
+ handleWebAuthnRegistration(username: string, credentials: {
74
+ id: string;
75
+ rawId: string;
76
+ type: string;
77
+ response: any;
78
+ }, options?: {
79
+ setErrorMessage?: (message: string) => void;
80
+ setUserpub?: (pub: string) => void;
81
+ setSignedIn?: (signedIn: boolean) => void;
82
+ }): Promise<AuthResult>;
83
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ export declare const CONFIG: {
2
+ TIMEOUT: {
3
+ AUTH: number;
4
+ GUN: number;
5
+ WALLET: number;
6
+ };
7
+ PATHS: {
8
+ DERIVATION_BASE: string;
9
+ DEFAULT_INDEX: number;
10
+ };
11
+ STORAGE_KEYS: {
12
+ ENTROPY: string;
13
+ GUN_PAIR: string;
14
+ WALLET_PATHS: string;
15
+ SESSION: string;
16
+ };
17
+ GUN_TABLES: {
18
+ USERS: string;
19
+ WALLET_PATHS: string;
20
+ AUTHENTICATIONS: string;
21
+ WEBAUTHN: string;
22
+ STEALTH: string;
23
+ MOM_MESSAGES: string;
24
+ MOM_MESSAGE_BLOCKS: string;
25
+ MOM_MESSAGE_REPLIES: string;
26
+ MOM_MESSAGE_UPDATES: string;
27
+ MOM_MESSAGE_DELETIONS: string;
28
+ };
29
+ AUTH: {
30
+ MIN_PASSWORD_LENGTH: number;
31
+ MAX_USERNAME_LENGTH: number;
32
+ MIN_USERNAME_LENGTH: number;
33
+ };
34
+ PREFIX: string;
35
+ PEERS: string[];
36
+ MESSAGE_TO_SIGN: string;
37
+ DEFAULT_RPC_URL: string;
38
+ };
39
+ export default CONFIG;