shogun-core 5.2.0 → 5.2.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 (185) hide show
  1. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
  2. package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
  3. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
  4. package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
  5. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
  6. package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
  7. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
  8. package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
  9. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
  10. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
  11. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
  12. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
  13. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
  14. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
  15. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
  16. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
  17. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
  18. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
  19. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
  20. package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
  21. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
  22. package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
  23. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
  24. package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
  25. package/dist/browser/shogun-core.js +160386 -0
  26. package/dist/browser/shogun-core.js.map +1 -0
  27. package/dist/config/simplified-config.js +236 -0
  28. package/dist/core.js +329 -0
  29. package/dist/crypto/asymmetric.js +99 -0
  30. package/dist/crypto/double-ratchet.js +370 -0
  31. package/dist/crypto/file-encryption.js +213 -0
  32. package/dist/crypto/hashing.js +87 -0
  33. package/dist/crypto/index.js +34 -0
  34. package/dist/crypto/mls-codec.js +202 -0
  35. package/dist/crypto/mls.js +550 -0
  36. package/dist/crypto/pgp.js +390 -0
  37. package/dist/crypto/random-generation.js +341 -0
  38. package/dist/crypto/sframe.js +350 -0
  39. package/dist/crypto/signal-protocol.js +376 -0
  40. package/dist/crypto/symmetric.js +91 -0
  41. package/dist/crypto/types.js +2 -0
  42. package/dist/crypto/utils.js +140 -0
  43. package/dist/examples/auth-test.js +253 -0
  44. package/dist/examples/crypto-identity-example.js +151 -0
  45. package/dist/examples/crypto-working-test.js +83 -0
  46. package/dist/examples/double-ratchet-test.js +155 -0
  47. package/dist/examples/mls-advanced-example.js +294 -0
  48. package/dist/examples/mls-sframe-test.js +304 -0
  49. package/dist/examples/pgp-example.js +200 -0
  50. package/dist/examples/quick-auth-test.js +61 -0
  51. package/dist/examples/random-generation-test.js +151 -0
  52. package/dist/examples/signal-protocol-test.js +38 -0
  53. package/dist/examples/simple-api-test.js +114 -0
  54. package/dist/examples/simple-crypto-identity-example.js +84 -0
  55. package/dist/examples/timeout-test.js +227 -0
  56. package/dist/examples/zkproof-credentials-example.js +212 -0
  57. package/dist/examples/zkproof-example.js +201 -0
  58. package/dist/gundb/api.js +435 -0
  59. package/dist/gundb/crypto.js +283 -0
  60. package/dist/gundb/db.js +1946 -0
  61. package/dist/gundb/derive.js +232 -0
  62. package/dist/gundb/errors.js +76 -0
  63. package/dist/gundb/index.js +22 -0
  64. package/dist/gundb/rxjs.js +447 -0
  65. package/dist/gundb/types.js +5 -0
  66. package/dist/index.js +58 -0
  67. package/dist/interfaces/common.js +2 -0
  68. package/dist/interfaces/events.js +40 -0
  69. package/dist/interfaces/plugin.js +2 -0
  70. package/dist/interfaces/shogun.js +37 -0
  71. package/dist/managers/AuthManager.js +226 -0
  72. package/dist/managers/CoreInitializer.js +228 -0
  73. package/dist/managers/CryptoIdentityManager.js +366 -0
  74. package/dist/managers/EventManager.js +70 -0
  75. package/dist/managers/PluginManager.js +299 -0
  76. package/dist/plugins/base.js +50 -0
  77. package/dist/plugins/index.js +32 -0
  78. package/dist/plugins/nostr/index.js +20 -0
  79. package/dist/plugins/nostr/nostrConnector.js +419 -0
  80. package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
  81. package/dist/plugins/nostr/nostrSigner.js +319 -0
  82. package/dist/plugins/nostr/types.js +2 -0
  83. package/dist/plugins/smartwallet/index.js +18 -0
  84. package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
  85. package/dist/plugins/smartwallet/types.js +2 -0
  86. package/dist/plugins/web3/index.js +20 -0
  87. package/dist/plugins/web3/types.js +2 -0
  88. package/dist/plugins/web3/web3Connector.js +533 -0
  89. package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
  90. package/dist/plugins/web3/web3Signer.js +314 -0
  91. package/dist/plugins/webauthn/index.js +19 -0
  92. package/dist/plugins/webauthn/types.js +14 -0
  93. package/dist/plugins/webauthn/webauthn.js +496 -0
  94. package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
  95. package/dist/plugins/webauthn/webauthnSigner.js +310 -0
  96. package/dist/plugins/zkproof/index.js +53 -0
  97. package/dist/plugins/zkproof/types.js +2 -0
  98. package/dist/plugins/zkproof/zkCredentials.js +213 -0
  99. package/dist/plugins/zkproof/zkProofConnector.js +198 -0
  100. package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
  101. package/dist/storage/storage.js +145 -0
  102. package/dist/types/config/simplified-config.d.ts +114 -0
  103. package/dist/types/core.d.ts +305 -0
  104. package/dist/types/crypto/asymmetric.d.ts +6 -0
  105. package/dist/types/crypto/double-ratchet.d.ts +22 -0
  106. package/dist/types/crypto/file-encryption.d.ts +19 -0
  107. package/dist/types/crypto/hashing.d.ts +9 -0
  108. package/dist/types/crypto/index.d.ts +13 -0
  109. package/dist/types/crypto/mls-codec.d.ts +39 -0
  110. package/dist/types/crypto/mls.d.ts +130 -0
  111. package/dist/types/crypto/pgp.d.ts +95 -0
  112. package/dist/types/crypto/random-generation.d.ts +35 -0
  113. package/dist/types/crypto/sframe.d.ts +102 -0
  114. package/dist/types/crypto/signal-protocol.d.ts +26 -0
  115. package/dist/types/crypto/symmetric.d.ts +9 -0
  116. package/dist/types/crypto/types.d.ts +144 -0
  117. package/dist/types/crypto/utils.d.ts +22 -0
  118. package/dist/types/examples/auth-test.d.ts +8 -0
  119. package/dist/types/examples/crypto-identity-example.d.ts +5 -0
  120. package/dist/types/examples/crypto-working-test.d.ts +1 -0
  121. package/dist/types/examples/double-ratchet-test.d.ts +1 -0
  122. package/dist/types/examples/mls-advanced-example.d.ts +53 -0
  123. package/dist/types/examples/mls-sframe-test.d.ts +1 -0
  124. package/dist/types/examples/pgp-example.d.ts +75 -0
  125. package/dist/types/examples/quick-auth-test.d.ts +8 -0
  126. package/dist/types/examples/random-generation-test.d.ts +1 -0
  127. package/dist/types/examples/signal-protocol-test.d.ts +1 -0
  128. package/dist/types/examples/simple-api-test.d.ts +10 -0
  129. package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
  130. package/dist/types/examples/timeout-test.d.ts +8 -0
  131. package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
  132. package/dist/types/examples/zkproof-example.d.ts +11 -0
  133. package/dist/types/gundb/api.d.ts +185 -0
  134. package/dist/types/gundb/crypto.d.ts +95 -0
  135. package/dist/types/gundb/db.d.ts +397 -0
  136. package/dist/types/gundb/derive.d.ts +21 -0
  137. package/dist/types/gundb/errors.d.ts +42 -0
  138. package/dist/types/gundb/index.d.ts +3 -0
  139. package/dist/types/gundb/rxjs.d.ts +110 -0
  140. package/dist/types/gundb/types.d.ts +255 -0
  141. package/dist/types/index.d.ts +16 -0
  142. package/dist/types/interfaces/common.d.ts +85 -0
  143. package/dist/types/interfaces/events.d.ts +131 -0
  144. package/dist/types/interfaces/plugin.d.ts +162 -0
  145. package/dist/types/interfaces/shogun.d.ts +208 -0
  146. package/dist/types/managers/AuthManager.d.ts +72 -0
  147. package/dist/types/managers/CoreInitializer.d.ts +40 -0
  148. package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
  149. package/dist/types/managers/EventManager.d.ts +49 -0
  150. package/dist/types/managers/PluginManager.d.ts +145 -0
  151. package/dist/types/plugins/base.d.ts +35 -0
  152. package/dist/types/plugins/index.d.ts +18 -0
  153. package/dist/types/plugins/nostr/index.d.ts +4 -0
  154. package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
  155. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
  156. package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
  157. package/dist/types/plugins/nostr/types.d.ts +122 -0
  158. package/dist/types/plugins/smartwallet/index.d.ts +2 -0
  159. package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
  160. package/dist/types/plugins/smartwallet/types.d.ts +80 -0
  161. package/dist/types/plugins/web3/index.d.ts +4 -0
  162. package/dist/types/plugins/web3/types.d.ts +107 -0
  163. package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
  164. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
  165. package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
  166. package/dist/types/plugins/webauthn/index.d.ts +3 -0
  167. package/dist/types/plugins/webauthn/types.d.ts +183 -0
  168. package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
  169. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
  170. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
  171. package/dist/types/plugins/zkproof/index.d.ts +48 -0
  172. package/dist/types/plugins/zkproof/types.d.ts +123 -0
  173. package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
  174. package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
  175. package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
  176. package/dist/types/storage/storage.d.ts +51 -0
  177. package/dist/types/utils/errorHandler.d.ts +119 -0
  178. package/dist/types/utils/eventEmitter.d.ts +39 -0
  179. package/dist/types/utils/seedPhrase.d.ts +50 -0
  180. package/dist/types/utils/validation.d.ts +27 -0
  181. package/dist/utils/errorHandler.js +246 -0
  182. package/dist/utils/eventEmitter.js +79 -0
  183. package/dist/utils/seedPhrase.js +97 -0
  184. package/dist/utils/validation.js +81 -0
  185. package/package.json +10 -1
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Simplified API layer focused on valuable helper methods.
3
+ * Provides quick-start initialization and high-level convenience methods.
4
+ *
5
+ * For basic operations (get, put, set, remove, auth), use DataBase directly.
6
+ * This class provides:
7
+ * - Quick initialization helpers (QuickStart, AutoQuickStart)
8
+ * - Array/Object conversion utilities for GunDB
9
+ * - High-level user data helpers (profile, settings, collections)
10
+ */
11
+ import { DataBase } from "./db";
12
+ /**
13
+ * Simple API wrapper that provides high-level helper methods.
14
+ * For basic operations, use the DataBase instance directly via the `database` property.
15
+ */
16
+ export declare class SimpleGunAPI {
17
+ private db;
18
+ /**
19
+ * Create a new SimpleGunAPI instance.
20
+ * @param db The DataBase instance to use.
21
+ */
22
+ constructor(db: DataBase);
23
+ /**
24
+ * Get direct access to the DataBase instance for full control.
25
+ * Use this for basic operations like get, put, set, remove, login, etc.
26
+ */
27
+ get database(): DataBase;
28
+ /**
29
+ * Convert an array to an indexed object for GunDB storage.
30
+ * GunDB doesn't store arrays natively, so this converts them to objects indexed by ID.
31
+ * Example: [{id: '1', ...}, {id: '2', ...}] => { "1": {...}, "2": {...} }
32
+ * @param arr The array to convert (each item must have an 'id' property).
33
+ * @returns The indexed object suitable for GunDB storage.
34
+ */
35
+ arrayToIndexedObject<T extends {
36
+ id: string | number;
37
+ }>(arr: T[]): Record<string, T>;
38
+ /**
39
+ * Convert an indexed object back to an array.
40
+ * Reverses the arrayToIndexedObject conversion.
41
+ * Example: { "1": {...}, "2": {...} } => [{id: '1', ...}, {id: '2', ...}]
42
+ * @param indexedObj The indexed object to convert.
43
+ * @returns The array of items.
44
+ */
45
+ indexedObjectToArray<T>(indexedObj: Record<string, T> | null): T[];
46
+ /**
47
+ * @deprecated This method is unreliable with GunDB. Use direct GunDB operations instead.
48
+ * Store an array at a global path by converting it to an indexed object.
49
+ * @param path The global path to store the array at
50
+ * @param arr The array to store (each item must have an 'id' property)
51
+ * @returns True if successful, false otherwise
52
+ */
53
+ putArray<T extends {
54
+ id: string | number;
55
+ }>(path: string, arr: T[]): Promise<boolean>;
56
+ /**
57
+ * @deprecated This method is unreliable with GunDB. Use direct GunDB operations instead.
58
+ * Retrieve an array from a global path by converting from indexed object.
59
+ * @param path The global path to retrieve the array from
60
+ * @returns The array of items, or empty array on error
61
+ */
62
+ getArray<T>(path: string): Promise<T[]>;
63
+ /**
64
+ * Get all user data (returns user's entire data tree).
65
+ * Requires user to be logged in.
66
+ * @returns The complete user data tree, or null if not logged in or on error.
67
+ */
68
+ getAllUserData(): Promise<Record<string, unknown> | null>;
69
+ /**
70
+ * Update user profile with common fields.
71
+ * Provides a standardized location for user profile data.
72
+ * @param profileData Profile data to save (name, email, bio, avatar, etc.)
73
+ * @returns True if successful, false otherwise.
74
+ */
75
+ updateProfile(profileData: {
76
+ name?: string;
77
+ email?: string;
78
+ bio?: string;
79
+ avatar?: string;
80
+ [key: string]: unknown;
81
+ }): Promise<boolean>;
82
+ /**
83
+ * Get user profile data.
84
+ * @returns The user profile data, or null if not found or not logged in.
85
+ */
86
+ getProfile(): Promise<Record<string, unknown> | null>;
87
+ /**
88
+ * Save user settings.
89
+ * Provides a standardized location for application settings.
90
+ * @param settings Settings object to save.
91
+ * @returns True if successful, false otherwise.
92
+ */
93
+ saveSettings(settings: Record<string, unknown>): Promise<boolean>;
94
+ /**
95
+ * Get user settings.
96
+ * @returns The user settings, or null if not found or not logged in.
97
+ */
98
+ getSettings(): Promise<Record<string, unknown> | null>;
99
+ /**
100
+ * Save user preferences.
101
+ * Provides a standardized location for user preferences (distinct from settings).
102
+ * @param preferences Preferences object to save.
103
+ * @returns True if successful, false otherwise.
104
+ */
105
+ savePreferences(preferences: Record<string, unknown>): Promise<boolean>;
106
+ /**
107
+ * Get user preferences.
108
+ * @returns The user preferences, or null if not found or not logged in.
109
+ */
110
+ getPreferences(): Promise<Record<string, unknown> | null>;
111
+ /**
112
+ * Create a user collection with initial items.
113
+ * Provides a standardized location for user collections.
114
+ * @param collectionName The name of the collection.
115
+ * @param items The initial items for the collection.
116
+ * @returns True if successful, false otherwise.
117
+ */
118
+ createCollection<T = unknown>(collectionName: string, items: Record<string, T>): Promise<boolean>;
119
+ /**
120
+ * Add an item to a user collection.
121
+ * @param collectionName The name of the collection.
122
+ * @param itemId The ID of the item to add.
123
+ * @param item The item data.
124
+ * @returns True if successful, false otherwise.
125
+ */
126
+ addToCollection<T = unknown>(collectionName: string, itemId: string, item: T): Promise<boolean>;
127
+ /**
128
+ * Get a user collection.
129
+ * @param collectionName The name of the collection.
130
+ * @returns The collection data, or null if not found or not logged in.
131
+ */
132
+ getCollection(collectionName: string): Promise<Record<string, unknown> | null>;
133
+ /**
134
+ * Remove an item from a user collection.
135
+ * @param collectionName The name of the collection.
136
+ * @param itemId The ID of the item to remove.
137
+ * @returns True if successful, false otherwise.
138
+ */
139
+ removeFromCollection(collectionName: string, itemId: string): Promise<boolean>;
140
+ }
141
+ /**
142
+ * Factory function to create a simple API instance
143
+ */
144
+ export declare function createSimpleAPI(db: DataBase): SimpleGunAPI;
145
+ /**
146
+ * Quick start helper - creates a simple API with minimal configuration
147
+ */
148
+ export declare class QuickStart {
149
+ private db;
150
+ private simpleAPI;
151
+ constructor(gunInstance: any, appScope?: string);
152
+ init(): Promise<void>;
153
+ get api(): SimpleGunAPI;
154
+ get database(): DataBase;
155
+ }
156
+ /**
157
+ * Auto Quick Start helper - creates a simple API with automatic Gun instance creation
158
+ * No need to pass a Gun instance, it creates one automatically
159
+ */
160
+ export declare class AutoQuickStart {
161
+ private db;
162
+ private simpleAPI;
163
+ private gunInstance;
164
+ constructor(config?: {
165
+ peers?: string[];
166
+ appScope?: string;
167
+ [key: string]: any;
168
+ });
169
+ init(): Promise<void>;
170
+ get api(): SimpleGunAPI;
171
+ get database(): DataBase;
172
+ get gun(): any;
173
+ }
174
+ /**
175
+ * Global helper for quick setup
176
+ */
177
+ export declare function quickStart(gunInstance: any, appScope?: string): QuickStart;
178
+ /**
179
+ * Global helper for auto quick setup - creates Gun instance automatically
180
+ */
181
+ export declare function autoQuickStart(config?: {
182
+ peers?: string[];
183
+ appScope?: string;
184
+ [key: string]: any;
185
+ }): AutoQuickStart;
@@ -0,0 +1,95 @@
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;
@@ -0,0 +1,397 @@
1
+ /**
2
+ * GunDB class with enhanced features:
3
+ * - Dynamic peer linking
4
+ * - Support for remove/unset operations
5
+ * - Direct authentication through Gun.user()
6
+ */
7
+ import type { UserInfo, AuthCallback, EventData, EventListener } from "./types";
8
+ import type { IGunUserInstance, IGunChain, IGunInstance, ISEAPair, GunMessagePut } from "gun/types";
9
+ import type { AuthResult, SignUpResult } from "../interfaces/shogun";
10
+ import Gun from "gun/gun";
11
+ import SEA from "gun/sea";
12
+ import "gun/lib/then";
13
+ import "gun/lib/radix";
14
+ import "gun/lib/radisk";
15
+ import "gun/lib/store";
16
+ import "gun/lib/rindexed";
17
+ import "gun/lib/webrtc";
18
+ import derive, { DeriveOptions } from "./derive";
19
+ import { GunDataEventData, GunPeerEventData } from "../interfaces/events";
20
+ import { RxJS } from "./rxjs";
21
+ import * as GunErrors from "./errors";
22
+ import * as crypto from "./crypto";
23
+ declare class DataBase {
24
+ gun: IGunInstance;
25
+ user: IGunUserInstance | null;
26
+ crypto: typeof crypto;
27
+ sea: typeof SEA;
28
+ node: IGunChain<any, any, any, any>;
29
+ core: any;
30
+ private readonly onAuthCallbacks;
31
+ private readonly eventEmitter;
32
+ private _rxjs?;
33
+ private _cryptoIdentityManager?;
34
+ constructor(gun: IGunInstance, appScope?: string, core?: any);
35
+ /**
36
+ * Initialize the GunInstance asynchronously
37
+ * This method should be called after construction to perform async operations
38
+ */
39
+ initialize(appScope?: string): void;
40
+ private subscribeToAuthEvents;
41
+ private notifyAuthListeners;
42
+ /**
43
+ * Adds a new peer to the network
44
+ * @param peer URL of the peer to add
45
+ */
46
+ addPeer(peer: string): void;
47
+ /**
48
+ * Removes a peer from the network
49
+ * @param peer URL of the peer to remove
50
+ */
51
+ removePeer(peer: string): void;
52
+ /**
53
+ * Gets the list of currently connected peers
54
+ * @returns Array of peer URLs
55
+ */
56
+ getCurrentPeers(): string[];
57
+ /**
58
+ * Gets the list of all configured peers (connected and disconnected)
59
+ * @returns Array of peer URLs
60
+ */
61
+ getAllConfiguredPeers(): string[];
62
+ /**
63
+ * Gets detailed information about all peers
64
+ * @returns Object with peer information
65
+ */
66
+ getPeerInfo(): {
67
+ [peer: string]: {
68
+ connected: boolean;
69
+ status: string;
70
+ };
71
+ };
72
+ /**
73
+ * Reconnects to a specific peer
74
+ * @param peer URL of the peer to reconnect
75
+ */
76
+ reconnectToPeer(peer: string): void;
77
+ /**
78
+ * Clears all peers and optionally adds new ones
79
+ * @param newPeers Optional array of new peers to add
80
+ */
81
+ resetPeers(newPeers?: string[]): void;
82
+ /**
83
+ * Registers an authentication callback
84
+ * @param callback Function to call on auth events
85
+ * @returns Function to unsubscribe the callback
86
+ */
87
+ onAuth(callback: AuthCallback): () => void;
88
+ /**
89
+ * Helper method to navigate to a nested path by splitting and chaining .get() calls
90
+ * @param node Starting Gun node
91
+ * @param path Path string (e.g., "test/data/marco")
92
+ * @returns Gun node at the specified path
93
+ */
94
+ private navigateToPath;
95
+ /**
96
+ * Gets the Gun instance
97
+ * @returns Gun instance
98
+ */
99
+ getGun(): IGunInstance;
100
+ /**
101
+ * Gets the current user
102
+ * @returns Current user object or null
103
+ */
104
+ getCurrentUser(): UserInfo | null;
105
+ /**
106
+ * Gets the current user instance
107
+ * @returns User instance
108
+ */
109
+ getUser(): IGunUserInstance;
110
+ /**
111
+ * Gets a node at the specified path
112
+ * @param path Path to the node
113
+ * @returns Gun node
114
+ */
115
+ get(path: string): IGunChain<any, any>;
116
+ /**
117
+ * Gets data at the specified path (one-time read)
118
+ * @param path Path to get the data from
119
+ * @returns Promise resolving to the data
120
+ */
121
+ getData(path: string): Promise<any>;
122
+ /**
123
+ * Puts data at the specified path
124
+ * @param path Path to store data
125
+ * @param data Data to store
126
+ * @returns Promise resolving to operation result
127
+ */
128
+ put(path: string, data: any): Promise<GunMessagePut>;
129
+ /**
130
+ * Sets data at the specified path
131
+ * @param path Path to store data
132
+ * @param data Data to store
133
+ * @returns Promise resolving to operation result
134
+ */
135
+ set(path: string, data: any): Promise<GunMessagePut>;
136
+ /**
137
+ * Removes data at the specified path
138
+ * @param path Path to remove
139
+ * @returns Promise resolving to operation result
140
+ */
141
+ remove(path: string): Promise<GunMessagePut>;
142
+ /**
143
+ * Checks if a user is currently logged in
144
+ * @returns True if logged in
145
+ */
146
+ isLoggedIn(): boolean;
147
+ /**
148
+ * Attempts to restore user session from local storage
149
+ * @returns Promise resolving to session restoration result
150
+ */
151
+ restoreSession(): {
152
+ success: boolean;
153
+ userPub?: string;
154
+ error?: string;
155
+ };
156
+ logout(): void;
157
+ /**
158
+ * Accesses the RxJS module for reactive programming
159
+ * @returns GunRxJS instance
160
+ */
161
+ rx(): RxJS;
162
+ /**
163
+ * Validates password strength according to security requirements
164
+ */
165
+ private validatePasswordStrength;
166
+ /**
167
+ * Validates signup credentials with enhanced security
168
+ */
169
+ private validateSignupCredentials;
170
+ /**
171
+ * Creates a new user in Gun
172
+ */
173
+ private createNewUser;
174
+ /**
175
+ * Authenticates user after creation
176
+ */
177
+ private authenticateNewUser;
178
+ /**
179
+ * Signs up a new user using direct Gun authentication
180
+ * @param username Username
181
+ * @param password Password
182
+ * @param pair Optional SEA pair for Web3 login
183
+ * @returns Promise resolving to signup result
184
+ */
185
+ signUp(username: string, password: string, pair?: ISEAPair | null): Promise<SignUpResult>;
186
+ /**
187
+ * Creates a new user in Gun with pair-based authentication (for Web3/plugins)
188
+ */
189
+ private createNewUserWithPair;
190
+ private runPostAuthOnAuthResult;
191
+ /**
192
+ * Sets up comprehensive user tracking system for agile user lookup
193
+ * Creates multiple indexes for efficient user discovery
194
+ */
195
+ private setupComprehensiveUserTracking;
196
+ /**
197
+ * Creates alias index following GunDB pattern: ~@alias -> userPub
198
+ */
199
+ private createAliasIndex;
200
+ /**
201
+ * Creates username mapping: usernames/alias -> userPub
202
+ */
203
+ private createUsernameMapping;
204
+ /**
205
+ * Creates user registry: users/userPub -> user data
206
+ */
207
+ private createUserRegistry;
208
+ /**
209
+ * Creates reverse lookup: userPub -> alias
210
+ */
211
+ private createReverseLookup;
212
+ /**
213
+ * Creates epub index: epubKeys/epub -> userPub
214
+ */
215
+ private createEpubIndex;
216
+ /**
217
+ * Creates user metadata in user's own node
218
+ */
219
+ private createUserMetadata;
220
+ /**
221
+ * Gets user information by alias using the comprehensive tracking system
222
+ * @param alias Username/alias to lookup
223
+ * @returns Promise resolving to user information or null if not found
224
+ */
225
+ getUserByAlias(alias: string): Promise<{
226
+ userPub: string;
227
+ epub: string | null;
228
+ username: string;
229
+ registeredAt: number;
230
+ lastSeen: number;
231
+ } | null>;
232
+ /**
233
+ * Gets user information by public key
234
+ * @param userPub User's public key
235
+ * @returns Promise resolving to user information or null if not found
236
+ */
237
+ getUserDataByPub(userPub: string): Promise<{
238
+ userPub: string;
239
+ epub: string | null;
240
+ username: string;
241
+ registeredAt: number;
242
+ lastSeen: number;
243
+ } | null>;
244
+ /**
245
+ * Gets user public key by encryption public key (epub)
246
+ * @param epub User's encryption public key
247
+ * @returns Promise resolving to user public key or null if not found
248
+ */
249
+ getUserPubByEpub(epub: string): Promise<string | null>;
250
+ /**
251
+ * Gets user alias by public key
252
+ * @param userPub User's public key
253
+ * @returns Promise resolving to user alias or null if not found
254
+ */
255
+ getUserAliasByPub(userPub: string): Promise<string | null>;
256
+ /**
257
+ * Gets all registered users (for admin purposes)
258
+ * @returns Promise resolving to array of user information
259
+ */
260
+ getAllRegisteredUsers(): Promise<Array<{
261
+ userPub: string;
262
+ epub: string | null;
263
+ username: string;
264
+ registeredAt: number;
265
+ lastSeen: number;
266
+ }>>;
267
+ /**
268
+ * Updates user's last seen timestamp
269
+ * @param userPub User's public key
270
+ */
271
+ updateUserLastSeen(userPub: string): Promise<void>;
272
+ /**
273
+ * Performs authentication with Gun
274
+ */
275
+ private performAuthentication;
276
+ /**
277
+ * Builds login result object
278
+ */
279
+ private buildLoginResult;
280
+ /**
281
+ * Performs login with username and password
282
+ * @param username Username
283
+ * @param password Password
284
+ * @param pair SEA pair (optional)
285
+ * @returns Promise resolving to AuthResult object
286
+ */
287
+ login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
288
+ /**
289
+ * Performs login with GunDB pair directly
290
+ * @param username Username
291
+ * @param pair SEA pair
292
+ * @returns Promise resolving to AuthResult object
293
+ */
294
+ loginWithPair(username: string, pair: ISEAPair): Promise<AuthResult>;
295
+ private saveCredentials;
296
+ /**
297
+ * Sets up security questions and password hint
298
+ * @param username Username
299
+ * @param password Current password
300
+ * @param hint Password hint
301
+ * @param securityQuestions Array of security questions
302
+ * @param securityAnswers Array of answers to security questions
303
+ * @returns Promise resolving with the operation result
304
+ */
305
+ setPasswordHintWithSecurity(username: string, password: string, hint: string, securityQuestions: string[], securityAnswers: string[]): Promise<{
306
+ success: boolean;
307
+ error?: string;
308
+ }>;
309
+ /**
310
+ * Recovers password hint using security question answers
311
+ * @param username Username
312
+ * @param securityAnswers Array of answers to security questions
313
+ * @returns Promise resolving with the password hint
314
+ */
315
+ forgotPassword(username: string, securityAnswers: string[]): Promise<{
316
+ success: boolean;
317
+ hint?: string;
318
+ error?: string;
319
+ }>;
320
+ static Errors: typeof GunErrors;
321
+ /**
322
+ * Adds an event listener
323
+ * @param event Event name
324
+ * @param listener Event listener function
325
+ */
326
+ on(event: string | symbol, listener: EventListener): void;
327
+ /**
328
+ * Removes an event listener
329
+ * @param event Event name
330
+ * @param listener Event listener function
331
+ */
332
+ off(event: string | symbol, listener: EventListener): void;
333
+ /**
334
+ * Adds a one-time event listener
335
+ * @param event Event name
336
+ * @param listener Event listener function
337
+ */
338
+ once(event: string | symbol, listener: EventListener): void;
339
+ /**
340
+ * Emits an event
341
+ * @param event Event name
342
+ * @param data Event data
343
+ */
344
+ emit(event: string | symbol, data?: EventData): boolean;
345
+ /**
346
+ * Recall user session
347
+ */
348
+ recall(options?: {
349
+ sessionStorage?: boolean;
350
+ }): void;
351
+ /**
352
+ * Leave user session
353
+ */
354
+ leave(): void;
355
+ /**
356
+ * Set user data
357
+ */
358
+ setUserData(data: any): void;
359
+ /**
360
+ * Set password hint
361
+ */
362
+ setPasswordHint(hint: string): void;
363
+ /**
364
+ * Get password hint
365
+ */
366
+ getPasswordHint(): string | null;
367
+ /**
368
+ * Save session to storage
369
+ */
370
+ saveSession(session: any): void;
371
+ /**
372
+ * Load session from storage
373
+ */
374
+ loadSession(): any;
375
+ /**
376
+ * Clear session
377
+ */
378
+ clearSession(): void;
379
+ /**
380
+ * Get app scope
381
+ */
382
+ getAppScope(): string;
383
+ /**
384
+ * Get user public key
385
+ */
386
+ getUserPub(): string | null;
387
+ /**
388
+ * Check if user is authenticated
389
+ */
390
+ isAuthenticated(): boolean;
391
+ }
392
+ declare const createGun: (config: any) => IGunInstance<any>;
393
+ export { Gun, DataBase, SEA, RxJS, crypto, GunErrors, derive, createGun };
394
+ export default Gun;
395
+ export type { IGunUserInstance, IGunInstance, IGunChain } from "gun/types";
396
+ export type { GunDataEventData, GunPeerEventData };
397
+ export type { DeriveOptions };
@@ -0,0 +1,21 @@
1
+ export interface DeriveOptions {
2
+ includeSecp256k1Bitcoin?: boolean;
3
+ includeSecp256k1Ethereum?: boolean;
4
+ includeP256?: boolean;
5
+ }
6
+ export default function (pwd: any, extra: any, options?: DeriveOptions): Promise<{
7
+ pub: string;
8
+ priv: string;
9
+ epub: string;
10
+ epriv: string;
11
+ secp256k1Bitcoin: {
12
+ privateKey: string;
13
+ publicKey: string;
14
+ address: string;
15
+ };
16
+ secp256k1Ethereum: {
17
+ privateKey: string;
18
+ publicKey: string;
19
+ address: string;
20
+ };
21
+ }>;