shogun-core 3.0.3 → 3.0.4

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 (95) hide show
  1. package/package.json +1 -1
  2. package/dist/browser/shogun-core.js +0 -92128
  3. package/dist/browser/shogun-core.js.map +0 -1
  4. package/dist/config/simplified-config.js +0 -230
  5. package/dist/core.js +0 -338
  6. package/dist/gundb/crypto.js +0 -268
  7. package/dist/gundb/db.js +0 -1833
  8. package/dist/gundb/derive.js +0 -229
  9. package/dist/gundb/errors.js +0 -66
  10. package/dist/gundb/index.js +0 -6
  11. package/dist/gundb/restricted-put.js +0 -81
  12. package/dist/gundb/rxjs.js +0 -445
  13. package/dist/gundb/simple-api.js +0 -438
  14. package/dist/gundb/types.js +0 -4
  15. package/dist/index.js +0 -16
  16. package/dist/interfaces/common.js +0 -1
  17. package/dist/interfaces/events.js +0 -36
  18. package/dist/interfaces/plugin.js +0 -1
  19. package/dist/interfaces/shogun.js +0 -34
  20. package/dist/managers/AuthManager.js +0 -225
  21. package/dist/managers/CoreInitializer.js +0 -234
  22. package/dist/managers/EventManager.js +0 -67
  23. package/dist/managers/PluginManager.js +0 -296
  24. package/dist/migration-test.js +0 -91
  25. package/dist/plugins/base.js +0 -47
  26. package/dist/plugins/index.js +0 -15
  27. package/dist/plugins/nostr/index.js +0 -4
  28. package/dist/plugins/nostr/nostrConnector.js +0 -413
  29. package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -446
  30. package/dist/plugins/nostr/nostrSigner.js +0 -313
  31. package/dist/plugins/nostr/types.js +0 -1
  32. package/dist/plugins/oauth/index.js +0 -3
  33. package/dist/plugins/oauth/oauthConnector.js +0 -753
  34. package/dist/plugins/oauth/oauthPlugin.js +0 -396
  35. package/dist/plugins/oauth/types.js +0 -1
  36. package/dist/plugins/web3/index.js +0 -4
  37. package/dist/plugins/web3/types.js +0 -1
  38. package/dist/plugins/web3/web3Connector.js +0 -528
  39. package/dist/plugins/web3/web3ConnectorPlugin.js +0 -448
  40. package/dist/plugins/web3/web3Signer.js +0 -308
  41. package/dist/plugins/webauthn/index.js +0 -3
  42. package/dist/plugins/webauthn/types.js +0 -11
  43. package/dist/plugins/webauthn/webauthn.js +0 -478
  44. package/dist/plugins/webauthn/webauthnPlugin.js +0 -398
  45. package/dist/plugins/webauthn/webauthnSigner.js +0 -304
  46. package/dist/storage/storage.js +0 -147
  47. package/dist/types/config/simplified-config.d.ts +0 -114
  48. package/dist/types/core.d.ts +0 -305
  49. package/dist/types/gundb/crypto.d.ts +0 -95
  50. package/dist/types/gundb/db.d.ts +0 -404
  51. package/dist/types/gundb/derive.d.ts +0 -21
  52. package/dist/types/gundb/errors.d.ts +0 -42
  53. package/dist/types/gundb/index.d.ts +0 -3
  54. package/dist/types/gundb/restricted-put.d.ts +0 -15
  55. package/dist/types/gundb/rxjs.d.ts +0 -110
  56. package/dist/types/gundb/simple-api.d.ts +0 -90
  57. package/dist/types/gundb/types.d.ts +0 -264
  58. package/dist/types/index.d.ts +0 -14
  59. package/dist/types/interfaces/common.d.ts +0 -85
  60. package/dist/types/interfaces/events.d.ts +0 -131
  61. package/dist/types/interfaces/plugin.d.ts +0 -162
  62. package/dist/types/interfaces/shogun.d.ts +0 -215
  63. package/dist/types/managers/AuthManager.d.ts +0 -72
  64. package/dist/types/managers/CoreInitializer.d.ts +0 -40
  65. package/dist/types/managers/EventManager.d.ts +0 -49
  66. package/dist/types/managers/PluginManager.d.ts +0 -145
  67. package/dist/types/migration-test.d.ts +0 -16
  68. package/dist/types/plugins/base.d.ts +0 -35
  69. package/dist/types/plugins/index.d.ts +0 -14
  70. package/dist/types/plugins/nostr/index.d.ts +0 -4
  71. package/dist/types/plugins/nostr/nostrConnector.d.ts +0 -119
  72. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +0 -163
  73. package/dist/types/plugins/nostr/nostrSigner.d.ts +0 -105
  74. package/dist/types/plugins/nostr/types.d.ts +0 -122
  75. package/dist/types/plugins/oauth/index.d.ts +0 -3
  76. package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
  77. package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
  78. package/dist/types/plugins/oauth/types.d.ts +0 -114
  79. package/dist/types/plugins/web3/index.d.ts +0 -4
  80. package/dist/types/plugins/web3/types.d.ts +0 -107
  81. package/dist/types/plugins/web3/web3Connector.d.ts +0 -129
  82. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +0 -160
  83. package/dist/types/plugins/web3/web3Signer.d.ts +0 -114
  84. package/dist/types/plugins/webauthn/index.d.ts +0 -3
  85. package/dist/types/plugins/webauthn/types.d.ts +0 -162
  86. package/dist/types/plugins/webauthn/webauthn.d.ts +0 -129
  87. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +0 -158
  88. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +0 -91
  89. package/dist/types/storage/storage.d.ts +0 -50
  90. package/dist/types/utils/errorHandler.d.ts +0 -119
  91. package/dist/types/utils/eventEmitter.d.ts +0 -39
  92. package/dist/types/utils/validation.d.ts +0 -27
  93. package/dist/utils/errorHandler.js +0 -241
  94. package/dist/utils/eventEmitter.js +0 -76
  95. package/dist/utils/validation.js +0 -72
@@ -1,147 +0,0 @@
1
- /**
2
- * Storage implementation based on StorageMock
3
- * Provides a unified storage interface that works in both browser and non-browser environments
4
- * In browser environments, data is persisted to localStorage as a backup
5
- */
6
- export class ShogunStorage {
7
- store;
8
- isTestMode;
9
- useLocalStorage;
10
- /**
11
- * Initializes storage and loads any existing keypair from localStorage if available
12
- */
13
- constructor() {
14
- this.store = new Map();
15
- this.isTestMode = process.env.NODE_ENV === "test";
16
- this.useLocalStorage = false;
17
- // Debug: log the environment
18
- console.log("ShogunStorage: NODE_ENV =", process.env.NODE_ENV);
19
- console.log("ShogunStorage: isTestMode =", this.isTestMode);
20
- // In test mode, don't use localStorage to avoid test pollution
21
- if (this.isTestMode) {
22
- this.useLocalStorage = false;
23
- console.log("ShogunStorage: Test mode detected, localStorage disabled");
24
- return;
25
- }
26
- if (typeof localStorage !== "undefined") {
27
- console.log("ShogunStorage: localStorage is defined");
28
- try {
29
- // Probe localStorage without polluting expectations in tests
30
- const testKey = "_shogun_test";
31
- localStorage.setItem(testKey, testKey);
32
- localStorage.removeItem(testKey);
33
- this.useLocalStorage = true;
34
- console.log("ShogunStorage: localStorage enabled");
35
- const storedPair = localStorage.getItem("shogun_keypair");
36
- if (storedPair) {
37
- this.store.set("keypair", JSON.parse(storedPair));
38
- }
39
- }
40
- catch (error) {
41
- this.useLocalStorage = false;
42
- // Silence logs in tests; tests expect no console.error during constructor
43
- console.log("ShogunStorage: localStorage error:", error.message);
44
- }
45
- }
46
- else {
47
- console.log("ShogunStorage: localStorage is undefined");
48
- }
49
- }
50
- /**
51
- * Gets the stored keypair asynchronously
52
- * @returns Promise resolving to the keypair or null if not found
53
- */
54
- async getPair() {
55
- return this.getPairSync();
56
- }
57
- /**
58
- * Gets the stored keypair synchronously
59
- * @returns The keypair or null if not found
60
- */
61
- getPairSync() {
62
- return this.store.get("keypair") || null;
63
- }
64
- /**
65
- * Stores a keypair both in memory and localStorage if available
66
- * @param pair - The keypair to store
67
- */
68
- async setPair(pair) {
69
- this.store.set("keypair", pair);
70
- // Also save to localStorage in browser environments
71
- if (this.useLocalStorage) {
72
- try {
73
- localStorage.setItem("shogun_keypair", JSON.stringify(pair));
74
- }
75
- catch (error) {
76
- if (!this.isTestMode) {
77
- console.error("Error saving data to localStorage:", error);
78
- }
79
- }
80
- }
81
- }
82
- /**
83
- * Clears all stored data from both memory and localStorage
84
- */
85
- clearAll() {
86
- this.store.clear();
87
- // Also clear localStorage in browser environments
88
- if (this.useLocalStorage) {
89
- try {
90
- localStorage.removeItem("shogun_keypair");
91
- }
92
- catch (error) {
93
- if (!this.isTestMode) {
94
- console.error("Error removing data from localStorage:", error);
95
- }
96
- }
97
- }
98
- }
99
- /**
100
- * Gets an item from storage
101
- * @param key - The key to retrieve
102
- * @returns The stored value, or null if not found
103
- */
104
- getItem(key) {
105
- const value = this.store.get(key);
106
- if (value === undefined) {
107
- return null;
108
- }
109
- return value;
110
- }
111
- /**
112
- * Stores an item in both memory and localStorage if available
113
- * @param key - The key to store under
114
- * @param value - The value to store (must be JSON stringifiable)
115
- */
116
- setItem(key, value) {
117
- // Store the raw value as-is to preserve formatting
118
- this.store.set(key, value);
119
- if (this.useLocalStorage) {
120
- try {
121
- localStorage.setItem(key, typeof value === "string" ? value : JSON.stringify(value));
122
- }
123
- catch (error) {
124
- if (!this.isTestMode) {
125
- console.error(`Error saving ${key} to localStorage:`, error);
126
- }
127
- }
128
- }
129
- }
130
- /**
131
- * Removes an item from both memory and localStorage if available
132
- * @param key - The key to remove
133
- */
134
- removeItem(key) {
135
- this.store.delete(key);
136
- if (this.useLocalStorage) {
137
- try {
138
- localStorage.removeItem(key);
139
- }
140
- catch (error) {
141
- if (!this.isTestMode) {
142
- console.error(`Error removing ${key} from localStorage:`, error);
143
- }
144
- }
145
- }
146
- }
147
- }
@@ -1,114 +0,0 @@
1
- /**
2
- * Simplified configuration options to reduce complexity
3
- * Provides sensible defaults and easy-to-use presets
4
- */
5
- import { ShogunCoreConfig } from "../interfaces/shogun";
6
- /**
7
- * Preset configurations for common use cases
8
- */
9
- export declare const ShogunPresets: {
10
- /**
11
- * Minimal configuration for simple apps
12
- */
13
- minimal: () => ShogunCoreConfig;
14
- /**
15
- * Development configuration with local storage
16
- */
17
- development: () => ShogunCoreConfig;
18
- /**
19
- * Production configuration with multiple peers
20
- */
21
- production: (customPeers?: string[]) => ShogunCoreConfig;
22
- /**
23
- * Offline-first configuration
24
- */
25
- offline: () => ShogunCoreConfig;
26
- /**
27
- * Web3-enabled configuration
28
- */
29
- web3: () => ShogunCoreConfig;
30
- /**
31
- * WebAuthn-enabled configuration
32
- */
33
- webauthn: () => ShogunCoreConfig;
34
- };
35
- /**
36
- * Configuration builder for custom setups
37
- */
38
- export declare class ShogunConfigBuilder {
39
- private config;
40
- /**
41
- * Set Gun options
42
- */
43
- gunOptions(options: any): this;
44
- /**
45
- * Add peers
46
- */
47
- peers(peerList: string[]): this;
48
- /**
49
- * Enable WebAuthn
50
- */
51
- enableWebAuthn(rpName?: string, rpId?: string): this;
52
- /**
53
- * Enable Web3
54
- */
55
- enableWeb3(): this;
56
- /**
57
- * Enable Nostr
58
- */
59
- enableNostr(): this;
60
- /**
61
- * Set timeouts
62
- */
63
- timeouts(timeouts: {
64
- login?: number;
65
- signup?: number;
66
- operation?: number;
67
- }): this;
68
- /**
69
- * Build the final configuration
70
- */
71
- build(): ShogunCoreConfig;
72
- }
73
- /**
74
- * Helper functions for common configuration patterns
75
- */
76
- export declare const ConfigHelpers: {
77
- /**
78
- * Create a configuration for a specific environment
79
- */
80
- forEnvironment(env: "development" | "production" | "test"): ShogunCoreConfig;
81
- /**
82
- * Create a configuration with custom peers
83
- */
84
- withPeers(peers: string[]): ShogunCoreConfig;
85
- /**
86
- * Create a configuration for a specific use case
87
- */
88
- forUseCase(useCase: "chat" | "social" | "gaming" | "finance"): ShogunCoreConfig;
89
- };
90
- /**
91
- * Quick configuration functions
92
- */
93
- export declare const QuickConfig: {
94
- /**
95
- * Minimal setup for quick testing
96
- */
97
- test: () => ShogunCoreConfig;
98
- /**
99
- * Standard setup for most apps
100
- */
101
- standard: () => ShogunCoreConfig;
102
- /**
103
- * Setup with WebAuthn for secure apps
104
- */
105
- secure: () => ShogunCoreConfig;
106
- /**
107
- * Setup with Web3 for crypto apps
108
- */
109
- crypto: () => ShogunCoreConfig;
110
- /**
111
- * Offline setup for local development
112
- */
113
- local: () => ShogunCoreConfig;
114
- };
@@ -1,305 +0,0 @@
1
- import { ShogunEventMap } from "./interfaces/events";
2
- import { ShogunError } from "./utils/errorHandler";
3
- import { ShogunStorage } from "./storage/storage";
4
- import { IShogunCore, ShogunCoreConfig, AuthResult, SignUpResult, PluginCategory, AuthMethod, Wallets } from "./interfaces/shogun";
5
- import { ethers } from "ethers";
6
- import { ShogunPlugin } from "./interfaces/plugin";
7
- import { ISEAPair } from "gun";
8
- import { DataBase, RxJS, GunInstance, GunUserInstance } from "./gundb";
9
- import { PluginManager } from "./managers/PluginManager";
10
- /**
11
- * Main ShogunCore class - implements the IShogunCore interface
12
- *
13
- * This is the primary entry point for the Shogun SDK, providing access to:
14
- * - Decentralized database (GunInstance)
15
- * - Authentication methods (traditional, WebAuthn, MetaMask)
16
- * - Plugin system for extensibility
17
- * - RxJS integration for reactive programming
18
- *
19
- * @since 2.0.0
20
- */
21
- export declare class ShogunCore implements IShogunCore {
22
- static readonly API_VERSION = "^3.0.1";
23
- db: DataBase;
24
- storage: ShogunStorage;
25
- provider?: ethers.Provider;
26
- config: ShogunCoreConfig;
27
- rx: RxJS;
28
- _gun: GunInstance;
29
- _user: GunUserInstance | null;
30
- wallets: Wallets | undefined;
31
- pluginManager: PluginManager;
32
- private authManager;
33
- private eventManager;
34
- private coreInitializer;
35
- /**
36
- * Initialize the Shogun SDK
37
- * @param config - SDK Configuration object
38
- * @description Creates a new instance of ShogunCore with the provided configuration.
39
- * Initializes all required components including storage, event emitter, GunInstance connection,
40
- * and plugin system.
41
- */
42
- constructor(config: ShogunCoreConfig);
43
- /**
44
- * Access to the Gun instance
45
- * @returns The Gun instance
46
- */
47
- get gun(): GunInstance;
48
- /**
49
- * Access to the current user
50
- * @returns The current Gun user instance
51
- */
52
- get user(): GunUserInstance | null;
53
- /**
54
- * Gets the current user information
55
- * @returns Current user object or null
56
- */
57
- getCurrentUser(): {
58
- pub: string;
59
- user?: any;
60
- } | null;
61
- /**
62
- * Registers a plugin with the Shogun SDK
63
- * @param plugin Plugin instance to register
64
- * @throws Error if a plugin with the same name is already registered
65
- */
66
- register(plugin: ShogunPlugin): void;
67
- /**
68
- * Unregisters a plugin from the Shogun SDK
69
- * @param pluginName Name of the plugin to unregister
70
- */
71
- unregister(pluginName: string): void;
72
- /**
73
- * Retrieve a registered plugin by name
74
- * @param name Name of the plugin
75
- * @returns The requested plugin or undefined if not found
76
- * @template T Type of the plugin or its public interface
77
- */
78
- getPlugin<T = ShogunPlugin>(name: string): T | undefined;
79
- /**
80
- * Get information about all registered plugins
81
- * @returns Array of plugin information objects
82
- */
83
- getPluginsInfo(): Array<{
84
- name: string;
85
- version: string;
86
- category?: PluginCategory;
87
- description?: string;
88
- }>;
89
- /**
90
- * Get the total number of registered plugins
91
- * @returns Number of registered plugins
92
- */
93
- getPluginCount(): number;
94
- /**
95
- * Check if all plugins are properly initialized
96
- * @returns Object with initialization status for each plugin
97
- */
98
- getPluginsInitializationStatus(): Record<string, {
99
- initialized: boolean;
100
- error?: string;
101
- }>;
102
- /**
103
- * Validate plugin system integrity
104
- * @returns Object with validation results
105
- */
106
- validatePluginSystem(): {
107
- totalPlugins: number;
108
- initializedPlugins: number;
109
- failedPlugins: string[];
110
- warnings: string[];
111
- };
112
- /**
113
- * Attempt to reinitialize failed plugins
114
- * @returns Object with reinitialization results
115
- */
116
- reinitializeFailedPlugins(): {
117
- success: string[];
118
- failed: Array<{
119
- name: string;
120
- error: string;
121
- }>;
122
- };
123
- /**
124
- * Check plugin compatibility with current ShogunCore version
125
- * @returns Object with compatibility information
126
- */
127
- checkPluginCompatibility(): {
128
- compatible: Array<{
129
- name: string;
130
- version: string;
131
- }>;
132
- incompatible: Array<{
133
- name: string;
134
- version: string;
135
- reason: string;
136
- }>;
137
- unknown: Array<{
138
- name: string;
139
- version: string;
140
- }>;
141
- };
142
- /**
143
- * Get comprehensive debug information about the plugin system
144
- * @returns Complete plugin system debug information
145
- */
146
- getPluginSystemDebugInfo(): {
147
- shogunCoreVersion: string;
148
- totalPlugins: number;
149
- plugins: Array<{
150
- name: string;
151
- version: string;
152
- category?: PluginCategory;
153
- description?: string;
154
- initialized: boolean;
155
- error?: string;
156
- }>;
157
- initializationStatus: Record<string, {
158
- initialized: boolean;
159
- error?: string;
160
- }>;
161
- validation: {
162
- totalPlugins: number;
163
- initializedPlugins: number;
164
- failedPlugins: string[];
165
- warnings: string[];
166
- };
167
- compatibility: {
168
- compatible: Array<{
169
- name: string;
170
- version: string;
171
- }>;
172
- incompatible: Array<{
173
- name: string;
174
- version: string;
175
- reason: string;
176
- }>;
177
- unknown: Array<{
178
- name: string;
179
- version: string;
180
- }>;
181
- };
182
- };
183
- /**
184
- * Check if a plugin is registered
185
- * @param name Name of the plugin to check
186
- * @returns true if the plugin is registered, false otherwise
187
- */
188
- hasPlugin(name: string): boolean;
189
- /**
190
- * Get all plugins of a specific category
191
- * @param category Category of plugins to filter
192
- * @returns Array of plugins in the specified category
193
- */
194
- getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
195
- /**
196
- * Get an authentication method plugin by type
197
- * @param type The type of authentication method
198
- * @returns The authentication plugin or undefined if not available
199
- * This is a more modern approach to accessing authentication methods
200
- */
201
- getAuthenticationMethod(type: AuthMethod): ShogunPlugin | {
202
- login: (username: string, password: string) => Promise<AuthResult>;
203
- signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
204
- } | undefined;
205
- /**
206
- * Retrieve recent errors logged by the system
207
- * @param count - Number of errors to retrieve (default: 10)
208
- * @returns List of most recent errors
209
- */
210
- getRecentErrors(count?: number): ShogunError[];
211
- /**
212
- * Check if user is logged in
213
- * @returns {boolean} True if user is logged in, false otherwise
214
- * @description Verifies authentication status by checking GunInstance login state
215
- * and presence of authentication credentials in storage
216
- */
217
- isLoggedIn(): boolean;
218
- /**
219
- * Perform user logout
220
- * @description Logs out the current user from GunInstance and emits logout event.
221
- * If user is not authenticated, the logout operation is ignored.
222
- */
223
- logout(): void;
224
- /**
225
- * Authenticate user with username and password
226
- * @param username - Username
227
- * @param password - User password
228
- * @returns {Promise<AuthResult>} Promise with authentication result
229
- * @description Attempts to log in user with provided credentials.
230
- * Emits login event on success.
231
- */
232
- login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
233
- /**
234
- * Login with GunDB pair directly
235
- * @param pair - GunDB SEA pair for authentication
236
- * @returns {Promise<AuthResult>} Promise with authentication result
237
- * @description Authenticates user using a GunDB pair directly.
238
- * Emits login event on success.
239
- */
240
- loginWithPair(pair: ISEAPair): Promise<AuthResult>;
241
- /**
242
- * Register a new user with provided credentials
243
- * @param username - Username
244
- * @param password - Password
245
- * @param email - Email (optional)
246
- * @param pair - Pair of keys
247
- * @returns {Promise<SignUpResult>} Registration result
248
- * @description Creates a new user account with the provided credentials.
249
- * Validates password requirements and emits signup event on success.
250
- */
251
- signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
252
- /**
253
- * Emits an event through the core's event emitter.
254
- * Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
255
- * @param eventName The name of the event to emit.
256
- * @param data The data to pass with the event.
257
- * @returns {boolean} Indicates if the event had listeners.
258
- */
259
- emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
260
- /**
261
- * Add an event listener
262
- * @param eventName The name of the event to listen for
263
- * @param listener The callback function to execute when the event is emitted
264
- * @returns {this} Returns this instance for method chaining
265
- */
266
- on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
267
- /**
268
- * Add a one-time event listener
269
- * @param eventName The name of the event to listen for
270
- * @param listener The callback function to execute when the event is emitted
271
- * @returns {this} Returns this instance for method chaining
272
- */
273
- once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
274
- /**
275
- * Remove an event listener
276
- * @param eventName The name of the event to stop listening for
277
- * @param listener The callback function to remove
278
- * @returns {this} Returns this instance for method chaining
279
- */
280
- off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
281
- /**
282
- * Remove all listeners for a specific event or all events
283
- * @param eventName Optional. The name of the event to remove listeners for.
284
- * If not provided, all listeners for all events are removed.
285
- * @returns {this} Returns this instance for method chaining
286
- */
287
- removeAllListeners(eventName?: string | symbol): this;
288
- /**
289
- * Set the current authentication method
290
- * This is used by plugins to indicate which authentication method was used
291
- * @param method The authentication method used
292
- */
293
- setAuthMethod(method: AuthMethod): void;
294
- /**
295
- * Get the current authentication method
296
- * @returns The current authentication method or undefined if not set
297
- */
298
- getAuthMethod(): AuthMethod | undefined;
299
- /**
300
- * Saves the current user credentials to storage
301
- */
302
- saveCredentials(credentials: any): Promise<void>;
303
- getIsLoggedIn(): boolean;
304
- }
305
- export default ShogunCore;
@@ -1,95 +0,0 @@
1
- /**
2
- * Cryptographic utilities for GunDB integration.
3
- * Based on GunDB's SEA (Security, Encryption, Authorization) module.
4
- * @see https://github.com/amark/gun/wiki/Snippets
5
- */
6
- import { ISEAPair } from "gun";
7
- /**
8
- * Checks if a string is a valid GunDB hash
9
- * @param str - String to check
10
- * @returns True if string matches GunDB hash format (44 chars ending with =)
11
- */
12
- export declare function isHash(str: string): boolean;
13
- /**
14
- * Encrypts data with Gun.SEA
15
- * @param data Data to encrypt
16
- * @param key Encryption key
17
- * @returns Promise that resolves with the encrypted data
18
- */
19
- export declare function encrypt(data: any, key: string): Promise<string>;
20
- /**
21
- * Decrypts data with Gun.SEA
22
- * @param encryptedData Encrypted data
23
- * @param key Decryption key
24
- * @returns Promise that resolves with the decrypted data
25
- */
26
- export declare function decrypt(encryptedData: string, key: string): Promise<string | any>;
27
- /**
28
- * Encrypts data from a sender to a receiver using their public keys
29
- * @param data - Data to encrypt
30
- * @param sender - Sender's key pair
31
- * @param receiver - Receiver's public encryption key
32
- * @returns Promise resolving to encrypted data
33
- */
34
- export declare function encFor(data: any, sender: ISEAPair, receiver: {
35
- epub: string;
36
- }): Promise<any>;
37
- /**
38
- * Decrypts data from a sender using receiver's private key
39
- * @param data - Data to decrypt
40
- * @param sender - Sender's public encryption key
41
- * @param receiver - Receiver's key pair
42
- * @returns Promise resolving to decrypted data
43
- */
44
- export declare function decFrom(data: any, sender: {
45
- epub: string;
46
- }, receiver: ISEAPair): Promise<any>;
47
- /**
48
- * Creates a SHA-256 hash of text
49
- * @param text - Text to hash
50
- * @returns Promise resolving to hash string
51
- */
52
- export declare function hashText(text: string): Promise<any>;
53
- /**
54
- * Creates a hash of an object by stringifying it first
55
- * @param obj - Object to hash
56
- * @returns Promise resolving to hash and original stringified data
57
- */
58
- export declare function hashObj(obj: any): Promise<{
59
- hash: any;
60
- hashed: string;
61
- }>;
62
- /**
63
- * Generates a shared secret between two parties
64
- * @param epub - Public encryption key
65
- * @param pair - Key pair
66
- * @returns Promise resolving to shared secret
67
- */
68
- export declare function secret(epub: string, pair: ISEAPair): Promise<string>;
69
- /**
70
- * Creates a short hash using PBKDF2
71
- * @param text - Text to hash
72
- * @param salt - Salt for hashing
73
- * @returns Promise resolving to hex-encoded hash
74
- */
75
- export declare function getShortHash(text: string, salt?: string): Promise<any>;
76
- /**
77
- * Converts unsafe characters in hash to URL-safe versions
78
- * @param unsafe - String containing unsafe characters
79
- * @returns URL-safe string with encoded characters
80
- */
81
- export declare function safeHash(unsafe: string): any;
82
- /**
83
- * Converts URL-safe characters back to original hash characters
84
- * @param safe - URL-safe string
85
- * @returns Original string with decoded characters
86
- */
87
- export declare function unsafeHash(safe: string): any;
88
- /**
89
- * Safely parses JSON with fallback to default value
90
- * @param input - String to parse as JSON
91
- * @param def - Default value if parsing fails
92
- * @returns Parsed object or default value
93
- */
94
- export declare function safeJSONParse(input: any, def?: any): any;
95
- export declare function randomUUID(): string;