shogun-core 5.2.0 → 5.2.2
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 +145 -1143
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/shogun-core.js +160386 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +236 -0
- package/dist/core.js +329 -0
- package/dist/crypto/asymmetric.js +99 -0
- package/dist/crypto/double-ratchet.js +370 -0
- package/dist/crypto/file-encryption.js +213 -0
- package/dist/crypto/hashing.js +87 -0
- package/dist/crypto/index.js +34 -0
- package/dist/crypto/mls-codec.js +202 -0
- package/dist/crypto/mls.js +550 -0
- package/dist/crypto/pgp.js +390 -0
- package/dist/crypto/random-generation.js +341 -0
- package/dist/crypto/sframe.js +350 -0
- package/dist/crypto/signal-protocol.js +376 -0
- package/dist/crypto/symmetric.js +91 -0
- package/dist/crypto/types.js +2 -0
- package/dist/crypto/utils.js +140 -0
- package/dist/examples/auth-test.js +253 -0
- package/dist/examples/crypto-identity-example.js +151 -0
- package/dist/examples/crypto-working-test.js +83 -0
- package/dist/examples/double-ratchet-test.js +155 -0
- package/dist/examples/mls-advanced-example.js +294 -0
- package/dist/examples/mls-sframe-test.js +304 -0
- package/dist/examples/pgp-example.js +200 -0
- package/dist/examples/quick-auth-test.js +61 -0
- package/dist/examples/random-generation-test.js +151 -0
- package/dist/examples/signal-protocol-test.js +38 -0
- package/dist/examples/simple-api-test.js +114 -0
- package/dist/examples/simple-crypto-identity-example.js +84 -0
- package/dist/examples/timeout-test.js +227 -0
- package/dist/examples/zkproof-credentials-example.js +212 -0
- package/dist/examples/zkproof-example.js +201 -0
- package/dist/gundb/api.js +435 -0
- package/dist/gundb/crypto.js +283 -0
- package/dist/gundb/db.js +1946 -0
- package/dist/gundb/derive.js +232 -0
- package/dist/gundb/errors.js +76 -0
- package/dist/gundb/index.js +22 -0
- package/dist/gundb/rxjs.js +447 -0
- package/dist/gundb/types.js +5 -0
- package/dist/index.js +58 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/interfaces/events.js +40 -0
- package/dist/interfaces/plugin.js +2 -0
- package/dist/interfaces/shogun.js +37 -0
- package/dist/managers/AuthManager.js +226 -0
- package/dist/managers/CoreInitializer.js +228 -0
- package/dist/managers/CryptoIdentityManager.js +366 -0
- package/dist/managers/EventManager.js +70 -0
- package/dist/managers/PluginManager.js +299 -0
- package/dist/plugins/base.js +50 -0
- package/dist/plugins/index.js +32 -0
- package/dist/plugins/nostr/index.js +20 -0
- package/dist/plugins/nostr/nostrConnector.js +419 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
- package/dist/plugins/nostr/nostrSigner.js +319 -0
- package/dist/plugins/nostr/types.js +2 -0
- package/dist/plugins/smartwallet/index.js +18 -0
- package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
- package/dist/plugins/smartwallet/types.js +2 -0
- package/dist/plugins/web3/index.js +20 -0
- package/dist/plugins/web3/types.js +2 -0
- package/dist/plugins/web3/web3Connector.js +533 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
- package/dist/plugins/web3/web3Signer.js +314 -0
- package/dist/plugins/webauthn/index.js +19 -0
- package/dist/plugins/webauthn/types.js +14 -0
- package/dist/plugins/webauthn/webauthn.js +496 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
- package/dist/plugins/webauthn/webauthnSigner.js +310 -0
- package/dist/plugins/zkproof/index.js +53 -0
- package/dist/plugins/zkproof/types.js +2 -0
- package/dist/plugins/zkproof/zkCredentials.js +213 -0
- package/dist/plugins/zkproof/zkProofConnector.js +198 -0
- package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
- package/dist/storage/storage.js +145 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/crypto/asymmetric.d.ts +6 -0
- package/dist/types/crypto/double-ratchet.d.ts +22 -0
- package/dist/types/crypto/file-encryption.d.ts +19 -0
- package/dist/types/crypto/hashing.d.ts +9 -0
- package/dist/types/crypto/index.d.ts +13 -0
- package/dist/types/crypto/mls-codec.d.ts +39 -0
- package/dist/types/crypto/mls.d.ts +130 -0
- package/dist/types/crypto/pgp.d.ts +95 -0
- package/dist/types/crypto/random-generation.d.ts +35 -0
- package/dist/types/crypto/sframe.d.ts +102 -0
- package/dist/types/crypto/signal-protocol.d.ts +26 -0
- package/dist/types/crypto/symmetric.d.ts +9 -0
- package/dist/types/crypto/types.d.ts +144 -0
- package/dist/types/crypto/utils.d.ts +22 -0
- package/dist/types/examples/auth-test.d.ts +8 -0
- package/dist/types/examples/crypto-identity-example.d.ts +5 -0
- package/dist/types/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/examples/mls-advanced-example.d.ts +53 -0
- package/dist/types/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/examples/pgp-example.d.ts +75 -0
- package/dist/types/examples/quick-auth-test.d.ts +8 -0
- package/dist/types/examples/random-generation-test.d.ts +1 -0
- package/dist/types/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/examples/simple-api-test.d.ts +10 -0
- package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
- package/dist/types/examples/timeout-test.d.ts +8 -0
- package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- package/dist/types/gundb/api.d.ts +185 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +397 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/types.d.ts +255 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +208 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +18 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/smartwallet/index.d.ts +2 -0
- package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
- package/dist/types/plugins/smartwallet/types.d.ts +80 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +183 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/plugins/zkproof/index.d.ts +48 -0
- package/dist/types/plugins/zkproof/types.d.ts +123 -0
- package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
- package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
- package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
- package/dist/types/storage/storage.d.ts +51 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/seedPhrase.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +246 -0
- package/dist/utils/eventEmitter.js +79 -0
- package/dist/utils/seedPhrase.js +97 -0
- package/dist/utils/validation.js +81 -0
- package/package.json +10 -57
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { ShogunCore } from "../core";
|
|
2
|
+
import { PluginCategory } from "./shogun";
|
|
3
|
+
/**
|
|
4
|
+
* Interfaccia di base per tutti i plugin di ShogunCore
|
|
5
|
+
*/
|
|
6
|
+
export interface ShogunPlugin {
|
|
7
|
+
/** Nome univoco del plugin */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Versione del plugin */
|
|
10
|
+
version: string;
|
|
11
|
+
/** Descrizione opzionale del plugin */
|
|
12
|
+
description?: string;
|
|
13
|
+
/** Categoria del plugin (opzionale) */
|
|
14
|
+
_category?: PluginCategory;
|
|
15
|
+
/**
|
|
16
|
+
* Metodo opzionale per inizializzare il plugin
|
|
17
|
+
* @param core Istanza di ShogunCore
|
|
18
|
+
*/
|
|
19
|
+
initialize(core: ShogunCore): void;
|
|
20
|
+
/**
|
|
21
|
+
* Metodo opzionale per distruggere il plugin e liberare risorse
|
|
22
|
+
*/
|
|
23
|
+
destroy?(): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Interfaccia per la gestione dei plugin in ShogunCore
|
|
27
|
+
*/
|
|
28
|
+
export interface PluginManager {
|
|
29
|
+
/**
|
|
30
|
+
* Registra un nuovo plugin
|
|
31
|
+
* @param plugin Il plugin da registrare
|
|
32
|
+
*/
|
|
33
|
+
register(plugin: ShogunPlugin): void;
|
|
34
|
+
/**
|
|
35
|
+
* Cancella la registrazione di un plugin
|
|
36
|
+
* @param pluginName Nome del plugin da cancellare
|
|
37
|
+
*/
|
|
38
|
+
unregister(pluginName: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Recupera un plugin registrato per nome
|
|
41
|
+
* @param name Nome del plugin
|
|
42
|
+
* @returns Il plugin richiesto o undefined se non trovato
|
|
43
|
+
* @template T Tipo del plugin o dell'interfaccia pubblica del plugin
|
|
44
|
+
*/
|
|
45
|
+
getPlugin<T = ShogunPlugin>(name: string): T | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Verifica se un plugin è registrato
|
|
48
|
+
* @param name Nome del plugin da verificare
|
|
49
|
+
* @returns true se il plugin è registrato, false altrimenti
|
|
50
|
+
*/
|
|
51
|
+
hasPlugin(name: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Ottiene tutti i plugin di una determinata categoria
|
|
54
|
+
* @param category Categoria di plugin da filtrare
|
|
55
|
+
* @returns Array di plugin della categoria specificata
|
|
56
|
+
*/
|
|
57
|
+
getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
|
|
58
|
+
/**
|
|
59
|
+
* Ottiene informazioni su tutti i plugin registrati
|
|
60
|
+
* @returns Array di oggetti con informazioni sui plugin
|
|
61
|
+
*/
|
|
62
|
+
getPluginsInfo(): Array<{
|
|
63
|
+
name: string;
|
|
64
|
+
version: string;
|
|
65
|
+
category?: PluginCategory;
|
|
66
|
+
description?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Ottiene il numero totale di plugin registrati
|
|
70
|
+
* @returns Numero di plugin registrati
|
|
71
|
+
*/
|
|
72
|
+
getPluginCount(): number;
|
|
73
|
+
/**
|
|
74
|
+
* Verifica se tutti i plugin sono inizializzati correttamente
|
|
75
|
+
* @returns Oggetto con stato di inizializzazione per ogni plugin
|
|
76
|
+
*/
|
|
77
|
+
getPluginsInitializationStatus(): Record<string, {
|
|
78
|
+
initialized: boolean;
|
|
79
|
+
error?: string;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Valida l'integrità del sistema di plugin
|
|
83
|
+
* @returns Oggetto con risultati della validazione
|
|
84
|
+
*/
|
|
85
|
+
validatePluginSystem(): {
|
|
86
|
+
totalPlugins: number;
|
|
87
|
+
initializedPlugins: number;
|
|
88
|
+
failedPlugins: string[];
|
|
89
|
+
warnings: string[];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Tenta di reinizializzare i plugin falliti
|
|
93
|
+
* @returns Oggetto con risultati della reinizializzazione
|
|
94
|
+
*/
|
|
95
|
+
reinitializeFailedPlugins(): {
|
|
96
|
+
success: string[];
|
|
97
|
+
failed: Array<{
|
|
98
|
+
name: string;
|
|
99
|
+
error: string;
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Verifica la compatibilità dei plugin con la versione corrente di ShogunCore
|
|
104
|
+
* @returns Oggetto con informazioni sulla compatibilità
|
|
105
|
+
*/
|
|
106
|
+
checkPluginCompatibility(): {
|
|
107
|
+
compatible: Array<{
|
|
108
|
+
name: string;
|
|
109
|
+
version: string;
|
|
110
|
+
}>;
|
|
111
|
+
incompatible: Array<{
|
|
112
|
+
name: string;
|
|
113
|
+
version: string;
|
|
114
|
+
reason: string;
|
|
115
|
+
}>;
|
|
116
|
+
unknown: Array<{
|
|
117
|
+
name: string;
|
|
118
|
+
version: string;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Ottiene informazioni complete di debug sul sistema di plugin
|
|
123
|
+
* @returns Informazioni complete di debug del sistema di plugin
|
|
124
|
+
*/
|
|
125
|
+
getPluginSystemDebugInfo(): {
|
|
126
|
+
shogunCoreVersion: string;
|
|
127
|
+
totalPlugins: number;
|
|
128
|
+
plugins: Array<{
|
|
129
|
+
name: string;
|
|
130
|
+
version: string;
|
|
131
|
+
category?: PluginCategory;
|
|
132
|
+
description?: string;
|
|
133
|
+
initialized: boolean;
|
|
134
|
+
error?: string;
|
|
135
|
+
}>;
|
|
136
|
+
initializationStatus: Record<string, {
|
|
137
|
+
initialized: boolean;
|
|
138
|
+
error?: string;
|
|
139
|
+
}>;
|
|
140
|
+
validation: {
|
|
141
|
+
totalPlugins: number;
|
|
142
|
+
initializedPlugins: number;
|
|
143
|
+
failedPlugins: string[];
|
|
144
|
+
warnings: string[];
|
|
145
|
+
};
|
|
146
|
+
compatibility: {
|
|
147
|
+
compatible: Array<{
|
|
148
|
+
name: string;
|
|
149
|
+
version: string;
|
|
150
|
+
}>;
|
|
151
|
+
incompatible: Array<{
|
|
152
|
+
name: string;
|
|
153
|
+
version: string;
|
|
154
|
+
reason: string;
|
|
155
|
+
}>;
|
|
156
|
+
unknown: Array<{
|
|
157
|
+
name: string;
|
|
158
|
+
version: string;
|
|
159
|
+
}>;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { IGunInstance, IGunUserInstance } from "gun/types";
|
|
2
|
+
import { ISEAPair } from "gun";
|
|
3
|
+
import { ethers } from "ethers";
|
|
4
|
+
import { ShogunError } from "../utils/errorHandler";
|
|
5
|
+
import { DataBase } from "../gundb/db";
|
|
6
|
+
import { RxJS } from "../gundb/rxjs";
|
|
7
|
+
import { ShogunPlugin, PluginManager } from "./plugin";
|
|
8
|
+
import { ShogunStorage } from "../storage/storage";
|
|
9
|
+
import { ShogunEventMap } from "./events";
|
|
10
|
+
/**
|
|
11
|
+
* Standard plugin categories in ShogunCore
|
|
12
|
+
*/
|
|
13
|
+
export declare enum PluginCategory {
|
|
14
|
+
/** Authentication plugins (WebAuthn, MetaMask, Bitcoin) */
|
|
15
|
+
Authentication = "authentication",
|
|
16
|
+
/** Wallet management plugins */
|
|
17
|
+
Wallet = "wallet",
|
|
18
|
+
/** Privacy and anonymity plugins */
|
|
19
|
+
Privacy = "privacy",
|
|
20
|
+
/** Decentralized identity plugins */
|
|
21
|
+
Identity = "identity",
|
|
22
|
+
/** Other utility plugins */
|
|
23
|
+
Utility = "utility",
|
|
24
|
+
/** Messages plugins */
|
|
25
|
+
Messages = "messages",
|
|
26
|
+
/** Messaging plugins */
|
|
27
|
+
Other = "other"
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Standard names for built-in plugins
|
|
31
|
+
*/
|
|
32
|
+
export declare enum CorePlugins {
|
|
33
|
+
/** WebAuthn plugin */
|
|
34
|
+
WebAuthn = "webauthn",
|
|
35
|
+
/** Ethereum plugin */
|
|
36
|
+
Web3 = "web3",
|
|
37
|
+
/** Bitcoin wallet plugin */
|
|
38
|
+
Nostr = "nostr",
|
|
39
|
+
/** Zero-Knowledge Proof plugin */
|
|
40
|
+
ZkProof = "zkproof"
|
|
41
|
+
}
|
|
42
|
+
export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair";
|
|
43
|
+
export interface AuthEventData {
|
|
44
|
+
userPub?: string;
|
|
45
|
+
username?: string;
|
|
46
|
+
method: "password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair";
|
|
47
|
+
provider?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface AuthResult {
|
|
50
|
+
success: boolean;
|
|
51
|
+
error?: string;
|
|
52
|
+
userPub?: string;
|
|
53
|
+
username?: string;
|
|
54
|
+
sessionToken?: string;
|
|
55
|
+
authMethod?: AuthMethod;
|
|
56
|
+
sea?: {
|
|
57
|
+
pub: string;
|
|
58
|
+
priv: string;
|
|
59
|
+
epub: string;
|
|
60
|
+
epriv: string;
|
|
61
|
+
};
|
|
62
|
+
redirectUrl?: string;
|
|
63
|
+
pendingAuth?: boolean;
|
|
64
|
+
message?: string;
|
|
65
|
+
provider?: string;
|
|
66
|
+
isNewUser?: boolean;
|
|
67
|
+
user?: {
|
|
68
|
+
userPub?: string;
|
|
69
|
+
username?: string;
|
|
70
|
+
email?: string;
|
|
71
|
+
name?: string;
|
|
72
|
+
picture?: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sign up result interface
|
|
77
|
+
*/
|
|
78
|
+
export interface SignUpResult {
|
|
79
|
+
success: boolean;
|
|
80
|
+
userPub?: string;
|
|
81
|
+
username?: string;
|
|
82
|
+
pub?: string;
|
|
83
|
+
error?: string;
|
|
84
|
+
message?: string;
|
|
85
|
+
wallet?: any;
|
|
86
|
+
isNewUser?: boolean;
|
|
87
|
+
authMethod?: AuthMethod;
|
|
88
|
+
sessionToken?: string;
|
|
89
|
+
sea?: {
|
|
90
|
+
pub: string;
|
|
91
|
+
priv: string;
|
|
92
|
+
epub: string;
|
|
93
|
+
epriv: string;
|
|
94
|
+
};
|
|
95
|
+
seedPhrase?: string;
|
|
96
|
+
redirectUrl?: string;
|
|
97
|
+
pendingAuth?: boolean;
|
|
98
|
+
provider?: string;
|
|
99
|
+
user?: {
|
|
100
|
+
userPub?: string;
|
|
101
|
+
username?: string;
|
|
102
|
+
email?: string;
|
|
103
|
+
name?: string;
|
|
104
|
+
picture?: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface IShogunCore extends PluginManager {
|
|
108
|
+
gun: IGunInstance<any>;
|
|
109
|
+
_gun: IGunInstance<any>;
|
|
110
|
+
user: IGunUserInstance | null;
|
|
111
|
+
_user: IGunUserInstance | null;
|
|
112
|
+
db: DataBase;
|
|
113
|
+
rx: RxJS;
|
|
114
|
+
storage: ShogunStorage;
|
|
115
|
+
config: ShogunCoreConfig;
|
|
116
|
+
provider?: ethers.Provider;
|
|
117
|
+
signer?: ethers.Signer;
|
|
118
|
+
wallets?: Wallets;
|
|
119
|
+
pluginManager: any;
|
|
120
|
+
on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
121
|
+
off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
122
|
+
once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
123
|
+
removeAllListeners(eventName?: string | symbol): this;
|
|
124
|
+
emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
|
|
125
|
+
getRecentErrors(count?: number): ShogunError[];
|
|
126
|
+
login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
|
|
127
|
+
loginWithPair(username: string, pair: ISEAPair): Promise<AuthResult>;
|
|
128
|
+
signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
|
|
129
|
+
getAuthenticationMethod(type: AuthMethod): any;
|
|
130
|
+
setAuthMethod(method: AuthMethod): void;
|
|
131
|
+
getAuthMethod(): AuthMethod | undefined;
|
|
132
|
+
getCurrentUser(): {
|
|
133
|
+
pub: string;
|
|
134
|
+
user?: any;
|
|
135
|
+
} | null;
|
|
136
|
+
getIsLoggedIn(): boolean;
|
|
137
|
+
logout(): void;
|
|
138
|
+
isLoggedIn(): boolean;
|
|
139
|
+
saveCredentials(credentials: any): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* WebAuthn configuration
|
|
143
|
+
*/
|
|
144
|
+
export interface WebauthnConfig {
|
|
145
|
+
/** Enable WebAuthn */
|
|
146
|
+
enabled?: boolean;
|
|
147
|
+
/** Relying party name */
|
|
148
|
+
rpName?: string;
|
|
149
|
+
/** Relying party ID */
|
|
150
|
+
rpId?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Shogun SDK configuration
|
|
154
|
+
*/
|
|
155
|
+
export interface ShogunCoreConfig {
|
|
156
|
+
gunInstance?: IGunInstance<any>;
|
|
157
|
+
gunOptions?: any;
|
|
158
|
+
webauthn?: WebauthnConfig;
|
|
159
|
+
web3?: {
|
|
160
|
+
enabled?: boolean;
|
|
161
|
+
};
|
|
162
|
+
nostr?: {
|
|
163
|
+
enabled?: boolean;
|
|
164
|
+
};
|
|
165
|
+
zkproof?: {
|
|
166
|
+
enabled?: boolean;
|
|
167
|
+
defaultGroupId?: string;
|
|
168
|
+
deterministic?: boolean;
|
|
169
|
+
minEntropy?: number;
|
|
170
|
+
};
|
|
171
|
+
timeouts?: {
|
|
172
|
+
login?: number;
|
|
173
|
+
signup?: number;
|
|
174
|
+
operation?: number;
|
|
175
|
+
};
|
|
176
|
+
plugins?: {
|
|
177
|
+
autoRegister?: ShogunPlugin[];
|
|
178
|
+
};
|
|
179
|
+
disableAutoRecall?: boolean;
|
|
180
|
+
silent?: boolean;
|
|
181
|
+
}
|
|
182
|
+
export interface ShogunEvents {
|
|
183
|
+
error: (data: {
|
|
184
|
+
action: string;
|
|
185
|
+
message: string;
|
|
186
|
+
}) => void;
|
|
187
|
+
"auth:signup": (data: {
|
|
188
|
+
username: string;
|
|
189
|
+
userPub: string;
|
|
190
|
+
}) => void;
|
|
191
|
+
"auth:login": (data: {
|
|
192
|
+
username: string;
|
|
193
|
+
userPub: string;
|
|
194
|
+
}) => void;
|
|
195
|
+
"auth:logout": (data: Record<string, never>) => void;
|
|
196
|
+
}
|
|
197
|
+
export interface Wallets {
|
|
198
|
+
secp256k1Bitcoin: {
|
|
199
|
+
privateKey: string;
|
|
200
|
+
publicKey: string;
|
|
201
|
+
address: string;
|
|
202
|
+
};
|
|
203
|
+
secp256k1Ethereum: {
|
|
204
|
+
privateKey: string;
|
|
205
|
+
publicKey: string;
|
|
206
|
+
address: string;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { IShogunCore, AuthResult, SignUpResult, AuthMethod } from "../interfaces/shogun";
|
|
2
|
+
import { ISEAPair } from "gun";
|
|
3
|
+
/**
|
|
4
|
+
* Manages authentication operations for ShogunCore
|
|
5
|
+
*/
|
|
6
|
+
export declare class AuthManager {
|
|
7
|
+
private core;
|
|
8
|
+
private currentAuthMethod?;
|
|
9
|
+
constructor(core: IShogunCore);
|
|
10
|
+
/**
|
|
11
|
+
* Check if user is logged in
|
|
12
|
+
* @returns {boolean} True if user is logged in, false otherwise
|
|
13
|
+
* @description Verifies authentication status by checking GunInstance login state
|
|
14
|
+
* and presence of authentication credentials in storage
|
|
15
|
+
*/
|
|
16
|
+
isLoggedIn(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Perform user logout
|
|
19
|
+
* @description Logs out the current user from GunInstance and emits logout event.
|
|
20
|
+
* If user is not authenticated, the logout operation is ignored.
|
|
21
|
+
*/
|
|
22
|
+
logout(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticate user with username and password
|
|
25
|
+
* @param username - Username
|
|
26
|
+
* @param password - User password
|
|
27
|
+
* @returns {Promise<AuthResult>} Promise with authentication result
|
|
28
|
+
* @description Attempts to log in user with provided credentials.
|
|
29
|
+
* Emits login event on success.
|
|
30
|
+
*/
|
|
31
|
+
login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Login with GunDB pair directly
|
|
34
|
+
* @param pair - GunDB SEA pair for authentication
|
|
35
|
+
* @returns {Promise<AuthResult>} Promise with authentication result
|
|
36
|
+
* @description Authenticates user using a GunDB pair directly.
|
|
37
|
+
* Emits login event on success.
|
|
38
|
+
*/
|
|
39
|
+
loginWithPair(username: string, pair: ISEAPair): Promise<AuthResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Register a new user with provided credentials
|
|
42
|
+
* @param username - Username
|
|
43
|
+
* @param password - Password
|
|
44
|
+
* @param email - Email (optional)
|
|
45
|
+
* @param pair - Pair of keys
|
|
46
|
+
* @returns {Promise<SignUpResult>} Registration result
|
|
47
|
+
* @description Creates a new user account with the provided credentials.
|
|
48
|
+
* Validates password requirements and emits signup event on success.
|
|
49
|
+
*/
|
|
50
|
+
signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Set the current authentication method
|
|
53
|
+
* This is used by plugins to indicate which authentication method was used
|
|
54
|
+
* @param method The authentication method used
|
|
55
|
+
*/
|
|
56
|
+
setAuthMethod(method: AuthMethod): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get the current authentication method
|
|
59
|
+
* @returns The current authentication method or undefined if not set
|
|
60
|
+
*/
|
|
61
|
+
getAuthMethod(): AuthMethod | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get an authentication method plugin by type
|
|
64
|
+
* @param type The type of authentication method
|
|
65
|
+
* @returns The authentication plugin or undefined if not available
|
|
66
|
+
* This is a more modern approach to accessing authentication methods
|
|
67
|
+
*/
|
|
68
|
+
getAuthenticationMethod(type: AuthMethod): import("..").ShogunPlugin | {
|
|
69
|
+
login: (username: string, password: string) => Promise<AuthResult>;
|
|
70
|
+
signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
|
|
71
|
+
} | undefined;
|
|
72
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IShogunCore, ShogunCoreConfig } from "../interfaces/shogun";
|
|
2
|
+
/**
|
|
3
|
+
* Handles initialization of ShogunCore components
|
|
4
|
+
*/
|
|
5
|
+
export declare class CoreInitializer {
|
|
6
|
+
private core;
|
|
7
|
+
constructor(core: IShogunCore);
|
|
8
|
+
/**
|
|
9
|
+
* Initialize the Shogun SDK
|
|
10
|
+
* @param config - SDK Configuration object
|
|
11
|
+
* @description Creates a new instance of ShogunCore with the provided configuration.
|
|
12
|
+
* Initializes all required components including storage, event emitter, GunInstance connection,
|
|
13
|
+
* and plugin system.
|
|
14
|
+
*/
|
|
15
|
+
initialize(config: ShogunCoreConfig): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Initialize Gun instance
|
|
18
|
+
*/
|
|
19
|
+
private initializeGun;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize Gun user
|
|
22
|
+
*/
|
|
23
|
+
private initializeGunUser;
|
|
24
|
+
/**
|
|
25
|
+
* Setup Gun event forwarding
|
|
26
|
+
*/
|
|
27
|
+
private setupGunEventForwarding;
|
|
28
|
+
/**
|
|
29
|
+
* Setup wallet derivation
|
|
30
|
+
*/
|
|
31
|
+
private setupWalletDerivation;
|
|
32
|
+
/**
|
|
33
|
+
* Register built-in plugins based on configuration
|
|
34
|
+
*/
|
|
35
|
+
private registerBuiltinPlugins;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize async components
|
|
38
|
+
*/
|
|
39
|
+
private initializeDb;
|
|
40
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CryptoIdentityManager - Gestisce la generazione e il salvataggio delle identità crypto
|
|
3
|
+
* dopo l'autenticazione SEA dell'utente
|
|
4
|
+
*/
|
|
5
|
+
import type { IShogunCore } from "../interfaces/shogun";
|
|
6
|
+
import type { ISEAPair } from "gun/types";
|
|
7
|
+
import type { JWKKeyPair, SignalUser } from "../crypto/types";
|
|
8
|
+
import type { PGPKeyPair } from "../crypto/pgp";
|
|
9
|
+
/**
|
|
10
|
+
* Interfaccia per le identità crypto generate
|
|
11
|
+
*/
|
|
12
|
+
export interface CryptoIdentities {
|
|
13
|
+
rsa?: JWKKeyPair;
|
|
14
|
+
aes?: JsonWebKey;
|
|
15
|
+
signal?: SignalUser;
|
|
16
|
+
pgp?: PGPKeyPair;
|
|
17
|
+
mls?: {
|
|
18
|
+
groupId: string;
|
|
19
|
+
memberId: string;
|
|
20
|
+
};
|
|
21
|
+
sframe?: {
|
|
22
|
+
keyId: number;
|
|
23
|
+
};
|
|
24
|
+
createdAt: number;
|
|
25
|
+
version: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Risultato dell'operazione di generazione identità
|
|
29
|
+
*/
|
|
30
|
+
export interface IdentityGenerationResult {
|
|
31
|
+
success: boolean;
|
|
32
|
+
identities?: CryptoIdentities;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Risultato dell'operazione di salvataggio identità
|
|
37
|
+
*/
|
|
38
|
+
export interface IdentitySaveResult {
|
|
39
|
+
success: boolean;
|
|
40
|
+
savedKeys: string[];
|
|
41
|
+
error?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Risultato dell'operazione di recupero identità
|
|
45
|
+
*/
|
|
46
|
+
export interface IdentityRetrievalResult {
|
|
47
|
+
success: boolean;
|
|
48
|
+
identities?: CryptoIdentities;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Manager per la gestione delle identità crypto
|
|
53
|
+
* Genera automaticamente tutte le identità crypto disponibili dopo l'autenticazione SEA
|
|
54
|
+
*/
|
|
55
|
+
export declare class CryptoIdentityManager {
|
|
56
|
+
private core;
|
|
57
|
+
private pgpManager;
|
|
58
|
+
private mlsManager;
|
|
59
|
+
private sframeManager;
|
|
60
|
+
constructor(core: IShogunCore);
|
|
61
|
+
/**
|
|
62
|
+
* Genera tutte le identità crypto disponibili per un utente
|
|
63
|
+
* @param username - Nome utente
|
|
64
|
+
* @param seaPair - Coppia di chiavi SEA dell'utente
|
|
65
|
+
* @returns Promise con le identità generate
|
|
66
|
+
*/
|
|
67
|
+
generateAllIdentities(username: string, seaPair: ISEAPair): Promise<IdentityGenerationResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Cripta e salva le identità crypto su GunDB usando il SEA pair
|
|
70
|
+
* @param username - Nome utente
|
|
71
|
+
* @param identities - Identità crypto da salvare
|
|
72
|
+
* @param seaPair - Coppia di chiavi SEA per la crittografia
|
|
73
|
+
* @returns Promise con il risultato del salvataggio
|
|
74
|
+
*/
|
|
75
|
+
saveIdentitiesToGun(username: string, identities: CryptoIdentities, seaPair: ISEAPair): Promise<IdentitySaveResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Recupera e decripta le identità crypto da GunDB
|
|
78
|
+
* @param username - Nome utente
|
|
79
|
+
* @param seaPair - Coppia di chiavi SEA per la decrittografia
|
|
80
|
+
* @returns Promise con le identità recuperate
|
|
81
|
+
*/
|
|
82
|
+
retrieveIdentitiesFromGun(username: string, seaPair: ISEAPair): Promise<IdentityRetrievalResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Verifica se l'utente ha già delle identità crypto salvate
|
|
85
|
+
* @param username - Nome utente
|
|
86
|
+
* @returns Promise con il risultato della verifica
|
|
87
|
+
*/
|
|
88
|
+
hasStoredIdentities(username: string): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Processo completo: genera, salva e gestisce le identità crypto dopo l'autenticazione
|
|
91
|
+
* @param username - Nome utente
|
|
92
|
+
* @param seaPair - Coppia di chiavi SEA dell'utente
|
|
93
|
+
* @param forceRegenerate - Se true, rigenera anche se esistono già
|
|
94
|
+
* @returns Promise con il risultato del processo completo
|
|
95
|
+
*/
|
|
96
|
+
setupCryptoIdentities(username: string, seaPair: ISEAPair, forceRegenerate?: boolean): Promise<IdentityGenerationResult & IdentitySaveResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Ottiene le identità crypto dell'utente corrente
|
|
99
|
+
* @returns Promise con le identità dell'utente corrente
|
|
100
|
+
*/
|
|
101
|
+
getCurrentUserIdentities(): Promise<IdentityRetrievalResult>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ShogunEventEmitter, ShogunEventMap } from "../interfaces/events";
|
|
2
|
+
/**
|
|
3
|
+
* Manages event operations for ShogunCore
|
|
4
|
+
*/
|
|
5
|
+
export declare class EventManager {
|
|
6
|
+
private eventEmitter;
|
|
7
|
+
constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Emits an event through the core's event emitter.
|
|
10
|
+
* Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
|
|
11
|
+
* @param eventName The name of the event to emit.
|
|
12
|
+
* @param data The data to pass with the event.
|
|
13
|
+
* @returns {boolean} Indicates if the event had listeners.
|
|
14
|
+
*/
|
|
15
|
+
emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Add an event listener
|
|
18
|
+
* @param eventName The name of the event to listen for
|
|
19
|
+
* @param listener The callback function to execute when the event is emitted
|
|
20
|
+
* @returns {this} Returns this instance for method chaining
|
|
21
|
+
*/
|
|
22
|
+
on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
23
|
+
/**
|
|
24
|
+
* Add a one-time event listener
|
|
25
|
+
* @param eventName The name of the event to listen for
|
|
26
|
+
* @param listener The callback function to execute when the event is emitted
|
|
27
|
+
* @returns {this} Returns this instance for method chaining
|
|
28
|
+
*/
|
|
29
|
+
once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
30
|
+
/**
|
|
31
|
+
* Remove an event listener
|
|
32
|
+
* @param eventName The name of the event to stop listening for
|
|
33
|
+
* @param listener The callback function to remove
|
|
34
|
+
* @returns {this} Returns this instance for method chaining
|
|
35
|
+
*/
|
|
36
|
+
off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
|
|
37
|
+
/**
|
|
38
|
+
* Remove all listeners for a specific event or all events
|
|
39
|
+
* @param eventName Optional. The name of the event to remove listeners for.
|
|
40
|
+
* If not provided, all listeners for all events are removed.
|
|
41
|
+
* @returns {this} Returns this instance for method chaining
|
|
42
|
+
*/
|
|
43
|
+
removeAllListeners(eventName?: string | symbol): this;
|
|
44
|
+
/**
|
|
45
|
+
* Get the underlying event emitter instance
|
|
46
|
+
* @returns The ShogunEventEmitter instance
|
|
47
|
+
*/
|
|
48
|
+
getEventEmitter(): ShogunEventEmitter;
|
|
49
|
+
}
|