shogun-core 1.1.4 → 1.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 +61 -1327
- package/dist/browser/shogun-core.js +1 -1
- package/dist/browser/shogun-core.js.LICENSE.txt +0 -9
- package/dist/browser/shogun-core.light.js +1 -1
- package/dist/browser/shogun-core.vendors.light.js +1 -1
- package/dist/browser.js +27 -11
- package/dist/core.js +603 -0
- package/dist/{gun → gundb}/crypto.js +38 -8
- package/dist/gundb/gun.js +676 -0
- package/dist/{gun → gundb}/index.js +0 -5
- package/dist/{gun → gundb}/utils.js +6 -0
- package/dist/index.js +1 -807
- package/dist/plugins/index.js +15 -28
- package/dist/plugins/{stealth → nostr}/index.js +3 -4
- package/dist/plugins/nostr/nostrConnector.js +656 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +259 -0
- package/dist/plugins/{metamask → web3}/index.js +2 -2
- package/dist/plugins/{metamask/metamask.js → web3/web3Connector.js} +8 -8
- package/dist/plugins/{metamask/metamaskPlugin.js → web3/web3ConnectorPlugin.js} +32 -42
- package/dist/plugins/webauthn/webauthnPlugin.js +4 -0
- package/dist/types/browser.d.ts +9 -4
- package/dist/types/core.d.ts +221 -0
- package/dist/types/{gun → gundb}/crypto.d.ts +20 -5
- package/dist/types/{gun → gundb}/gun.d.ts +56 -28
- package/dist/types/gundb/index.d.ts +1 -0
- package/dist/types/{gun → gundb}/utils.d.ts +1 -0
- package/dist/types/index.d.ts +1 -282
- package/dist/types/plugins/index.d.ts +7 -10
- package/dist/types/plugins/nostr/index.d.ts +3 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +111 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +87 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/web3/index.d.ts +3 -0
- package/dist/types/plugins/{metamask → web3}/types.d.ts +4 -4
- package/dist/types/plugins/{metamask/metamask.d.ts → web3/web3Connector.d.ts} +7 -7
- package/dist/types/plugins/{metamask/metamaskPlugin.d.ts → web3/web3ConnectorPlugin.d.ts} +4 -4
- package/dist/types/shogun.js +40 -15
- package/dist/types/types/shogun.d.ts +67 -67
- package/dist/types/utils/errorHandler.d.ts +39 -36
- package/dist/types/utils/utility.d.ts +0 -4
- package/dist/utils/errorHandler.js +43 -40
- package/dist/utils/utility.js +0 -8
- package/package.json +2 -2
- package/dist/config.js +0 -18
- package/dist/gun/gun.js +0 -542
- package/dist/plugins/stealth/stealth.js +0 -176
- package/dist/plugins/stealth/stealthPlugin.js +0 -113
- package/dist/plugins/stealth/types.js +0 -2
- package/dist/plugins/utils/stubs/didStub.js +0 -35
- package/dist/plugins/utils/stubs/stealthStub.js +0 -35
- package/dist/plugins/utils/stubs/webauthnStub.js +0 -29
- package/dist/plugins/wallet/index.js +0 -20
- package/dist/plugins/wallet/types.js +0 -15
- package/dist/plugins/wallet/walletManager.js +0 -1832
- package/dist/plugins/wallet/walletPlugin.js +0 -236
- package/dist/types/config.d.ts +0 -15
- package/dist/types/gun/index.d.ts +0 -6
- package/dist/types/gun/types.d.ts +0 -2
- package/dist/types/plugins/metamask/index.d.ts +0 -3
- package/dist/types/plugins/stealth/index.d.ts +0 -3
- package/dist/types/plugins/stealth/stealth.d.ts +0 -93
- package/dist/types/plugins/stealth/stealthPlugin.d.ts +0 -60
- package/dist/types/plugins/stealth/types.d.ts +0 -93
- package/dist/types/plugins/utils/stubs/didStub.d.ts +0 -15
- package/dist/types/plugins/utils/stubs/stealthStub.d.ts +0 -15
- package/dist/types/plugins/utils/stubs/webauthnStub.d.ts +0 -13
- package/dist/types/plugins/wallet/index.d.ts +0 -3
- package/dist/types/plugins/wallet/types.d.ts +0 -167
- package/dist/types/plugins/wallet/walletManager.d.ts +0 -306
- package/dist/types/plugins/wallet/walletPlugin.d.ts +0 -126
- package/dist/types/utils/stubs/didStub.d.ts +0 -15
- package/dist/types/utils/stubs/stealthStub.d.ts +0 -15
- package/dist/types/utils/stubs/webauthnStub.d.ts +0 -13
- package/dist/utils/stubs/didStub.js +0 -35
- package/dist/utils/stubs/stealthStub.js +0 -35
- package/dist/utils/stubs/webauthnStub.js +0 -29
- /package/dist/{gun → gundb}/errors.js +0 -0
- /package/dist/{gun → gundb}/rxjs-integration.js +0 -0
- /package/dist/{gun → plugins/nostr}/types.js +0 -0
- /package/dist/plugins/{metamask → web3}/types.js +0 -0
- /package/dist/types/{gun → gundb}/errors.d.ts +0 -0
- /package/dist/types/{gun → gundb}/rxjs-integration.d.ts +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -1,283 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { ShogunStorage } from "./storage/storage";
|
|
3
|
-
import { IShogunCore, ShogunSDKConfig, AuthResult, SignUpResult, LoggingConfig, PluginCategory } from "./types/shogun";
|
|
4
|
-
import { IGunUserInstance } from "gun";
|
|
5
|
-
import { ethers } from "ethers";
|
|
6
|
-
import { ShogunError } from "./utils/errorHandler";
|
|
7
|
-
import { GunRxJS } from "./gun/rxjs-integration";
|
|
8
|
-
import { Observable } from "rxjs";
|
|
9
|
-
import { ShogunPlugin } from "./types/plugin";
|
|
10
|
-
import { GunInstance } from "./gun/types";
|
|
11
|
-
export { RelayVerifier } from "./contracts/utils";
|
|
12
|
-
export * from "./utils/errorHandler";
|
|
13
|
-
export type * from "./utils/errorHandler";
|
|
14
|
-
export * from "./gun/rxjs-integration";
|
|
1
|
+
export * from "./core";
|
|
15
2
|
export * from "./plugins";
|
|
16
|
-
export type * from "./types/plugin";
|
|
17
|
-
export * from "./contracts/entryPoint";
|
|
18
|
-
export * from "./contracts/utils";
|
|
19
|
-
export * from "./contracts/registry";
|
|
20
|
-
export * from "./contracts/relay";
|
|
21
|
-
export type * from "./contracts/entryPoint";
|
|
22
|
-
export type * from "./contracts/relay";
|
|
23
|
-
export type * from "./contracts/registry";
|
|
24
|
-
export type * from "./contracts/base";
|
|
25
|
-
export type * from "./contracts/utils";
|
|
26
|
-
/**
|
|
27
|
-
* Main ShogunCore class - implements the IShogunCore interface
|
|
28
|
-
*
|
|
29
|
-
* This is the primary entry point for the Shogun SDK, providing access to:
|
|
30
|
-
* - Decentralized database (GunDB)
|
|
31
|
-
* - Authentication methods (traditional, WebAuthn, MetaMask)
|
|
32
|
-
* - Plugin system for extensibility
|
|
33
|
-
* - DID (Decentralized Identity) management
|
|
34
|
-
* - RxJS integration for reactive programming
|
|
35
|
-
*
|
|
36
|
-
* @since 2.0.0
|
|
37
|
-
*/
|
|
38
|
-
export declare class ShogunCore implements IShogunCore {
|
|
39
|
-
/** Current API version - used for deprecation warnings and migration guidance */
|
|
40
|
-
static readonly API_VERSION = "2.0.0";
|
|
41
|
-
/** Gun database instance */
|
|
42
|
-
gun: GunInstance<any>;
|
|
43
|
-
/** Gun user instance */
|
|
44
|
-
user: IGunUserInstance<any> | null;
|
|
45
|
-
/** GunDB wrapper */
|
|
46
|
-
gundb: GunDB;
|
|
47
|
-
/** Storage implementation */
|
|
48
|
-
storage: ShogunStorage;
|
|
49
|
-
/** Event emitter for SDK events */
|
|
50
|
-
private readonly eventEmitter;
|
|
51
|
-
/** Ethereum provider */
|
|
52
|
-
provider?: ethers.Provider;
|
|
53
|
-
/** SDK configuration */
|
|
54
|
-
config: ShogunSDKConfig;
|
|
55
|
-
/** RxJS integration */
|
|
56
|
-
rx: GunRxJS;
|
|
57
|
-
/** Plugin registry */
|
|
58
|
-
private readonly plugins;
|
|
59
|
-
/**
|
|
60
|
-
* Initialize the Shogun SDK
|
|
61
|
-
* @param config - SDK Configuration object
|
|
62
|
-
* @description Creates a new instance of ShogunCore with the provided configuration.
|
|
63
|
-
* Initializes all required components including storage, event emitter, GunDB connection,
|
|
64
|
-
* and plugin system.
|
|
65
|
-
*/
|
|
66
|
-
constructor(config: ShogunSDKConfig);
|
|
67
|
-
/**
|
|
68
|
-
* Register built-in plugins based on configuration
|
|
69
|
-
* @private
|
|
70
|
-
*/
|
|
71
|
-
private registerBuiltinPlugins;
|
|
72
|
-
/**
|
|
73
|
-
* Register a new plugin with the SDK
|
|
74
|
-
* @param plugin The plugin to register
|
|
75
|
-
* @throws Error if a plugin with the same name is already registered
|
|
76
|
-
*/
|
|
77
|
-
register(plugin: ShogunPlugin): void;
|
|
78
|
-
/**
|
|
79
|
-
* Unregister a plugin from the SDK
|
|
80
|
-
* @param pluginName Name of the plugin to unregister
|
|
81
|
-
*/
|
|
82
|
-
unregister(pluginName: string): void;
|
|
83
|
-
/**
|
|
84
|
-
* Retrieve a registered plugin by name
|
|
85
|
-
* @param name Name of the plugin
|
|
86
|
-
* @returns The requested plugin or undefined if not found
|
|
87
|
-
* @template T Type of the plugin or its public interface
|
|
88
|
-
*/
|
|
89
|
-
getPlugin<T>(name: string): T | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* Check if a plugin is registered
|
|
92
|
-
* @param name Name of the plugin to check
|
|
93
|
-
* @returns true if the plugin is registered, false otherwise
|
|
94
|
-
*/
|
|
95
|
-
hasPlugin(name: string): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Get all plugins of a specific category
|
|
98
|
-
* @param category Category of plugins to filter
|
|
99
|
-
* @returns Array of plugins in the specified category
|
|
100
|
-
*/
|
|
101
|
-
getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
|
|
102
|
-
/**
|
|
103
|
-
* Get an authentication method plugin by type
|
|
104
|
-
* @param type The type of authentication method
|
|
105
|
-
* @returns The authentication plugin or undefined if not available
|
|
106
|
-
* This is a more modern approach to accessing authentication methods
|
|
107
|
-
*/
|
|
108
|
-
getAuthenticationMethod(type: "password" | "webauthn" | "metamask"): unknown;
|
|
109
|
-
/**
|
|
110
|
-
* Observe a Gun node for changes
|
|
111
|
-
* @param path - Path to observe (can be a string or a Gun chain)
|
|
112
|
-
* @returns Observable that emits whenever the node changes
|
|
113
|
-
*/
|
|
114
|
-
rxGet<T>(path: string): Observable<T>;
|
|
115
|
-
/**
|
|
116
|
-
* Match data based on Gun's '.map()' and convert to Observable
|
|
117
|
-
* @param path - Path to the collection
|
|
118
|
-
* @param matchFn - Optional function to filter results
|
|
119
|
-
* @returns Observable array of matched items
|
|
120
|
-
*/
|
|
121
|
-
match<T>(path: string | any, matchFn?: (data: any) => boolean): Observable<T[]>;
|
|
122
|
-
/**
|
|
123
|
-
* Put data and return an Observable
|
|
124
|
-
* @param path - Path where to put the data
|
|
125
|
-
* @param oata - Data to put
|
|
126
|
-
* @returns Observable that completes when the put is acknowledged
|
|
127
|
-
*/
|
|
128
|
-
rxPut<T>(path: string | any, data: T): Observable<T>;
|
|
129
|
-
/**
|
|
130
|
-
* Set data on a node and return an Observable
|
|
131
|
-
* @param path - Path to the collection
|
|
132
|
-
* @param data - Data to set
|
|
133
|
-
* @returns Observable that completes when the set is acknowledged
|
|
134
|
-
*/
|
|
135
|
-
rxSet<T>(path: string | any, data: T): Observable<T>;
|
|
136
|
-
/**
|
|
137
|
-
* Get data once and return as Observable
|
|
138
|
-
* @param path - Path to get data from
|
|
139
|
-
* @returns Observable that emits the data once
|
|
140
|
-
*/
|
|
141
|
-
rxOnce<T>(path: string | any): Observable<T>;
|
|
142
|
-
/**
|
|
143
|
-
* Compute derived values from gun data
|
|
144
|
-
* @param sources - Array of paths or observables to compute from
|
|
145
|
-
* @param computeFn - Function that computes a new value from the sources
|
|
146
|
-
* @returns Observable of computed values
|
|
147
|
-
*/
|
|
148
|
-
compute<T, R>(sources: Array<string | Observable<any>>, computeFn: (...values: T[]) => R): Observable<R>;
|
|
149
|
-
/**
|
|
150
|
-
* User put data and return an Observable (for authenticated users)
|
|
151
|
-
* @param path - Path where to put the data
|
|
152
|
-
* @param data - Data to put
|
|
153
|
-
* @returns Observable that completes when the put is acknowledged
|
|
154
|
-
*/
|
|
155
|
-
rxUserPut<T>(path: string, data: T): Observable<T>;
|
|
156
|
-
/**
|
|
157
|
-
* Observe user data
|
|
158
|
-
* @param path - Path to observe in user space
|
|
159
|
-
* @returns Observable that emits whenever the user data changes
|
|
160
|
-
*/
|
|
161
|
-
observeUser<T>(path: string): Observable<T>;
|
|
162
|
-
/**
|
|
163
|
-
* Retrieve recent errors logged by the system
|
|
164
|
-
* @param count - Number of errors to retrieve (default: 10)
|
|
165
|
-
* @returns List of most recent errors
|
|
166
|
-
*/
|
|
167
|
-
getRecentErrors(count?: number): ShogunError[];
|
|
168
|
-
/**
|
|
169
|
-
* Configure logging behavior for the Shogun SDK
|
|
170
|
-
* @param {LoggingConfig} config - Logging configuration object containing:
|
|
171
|
-
* - level: The minimum log level to display (error, warn, info, debug, trace)
|
|
172
|
-
* - logToConsole: Whether to output logs to the console (default: true)
|
|
173
|
-
* - customLogger: Optional custom logger implementation
|
|
174
|
-
* - logTimestamps: Whether to include timestamps in logs (default: true)
|
|
175
|
-
* @returns {void}
|
|
176
|
-
* @description Updates the logging configuration for the SDK. Changes take effect immediately
|
|
177
|
-
* for all subsequent log operations.
|
|
178
|
-
*/
|
|
179
|
-
configureLogging(config: LoggingConfig): void;
|
|
180
|
-
/**
|
|
181
|
-
* Check if user is logged in
|
|
182
|
-
* @returns {boolean} True if user is logged in, false otherwise
|
|
183
|
-
* @description Verifies authentication status by checking GunDB login state
|
|
184
|
-
* and presence of authentication credentials in storage
|
|
185
|
-
*/
|
|
186
|
-
isLoggedIn(): boolean;
|
|
187
|
-
/**
|
|
188
|
-
* Perform user logout
|
|
189
|
-
* @description Logs out the current user from GunDB and emits logout event.
|
|
190
|
-
* If user is not authenticated, the logout operation is ignored.
|
|
191
|
-
*/
|
|
192
|
-
logout(): void;
|
|
193
|
-
/**
|
|
194
|
-
* Authenticate user with username and password
|
|
195
|
-
* @param username - Username
|
|
196
|
-
* @param password - User password
|
|
197
|
-
* @returns {Promise<AuthResult>} Promise with authentication result
|
|
198
|
-
* @description Attempts to log in user with provided credentials.
|
|
199
|
-
* Emits login event on success.
|
|
200
|
-
*/
|
|
201
|
-
login(username: string, password: string): Promise<AuthResult>;
|
|
202
|
-
/**
|
|
203
|
-
* Register a new user with provided credentials
|
|
204
|
-
* @param username - Username
|
|
205
|
-
* @param password - Password
|
|
206
|
-
* @param passwordConfirmation - Password confirmation
|
|
207
|
-
* @returns {Promise<SignUpResult>} Registration result
|
|
208
|
-
* @description Creates a new user account with the provided credentials.
|
|
209
|
-
* Validates password requirements and emits signup event on success.
|
|
210
|
-
*/
|
|
211
|
-
signUp(username: string, password: string, passwordConfirmation?: string): Promise<SignUpResult>;
|
|
212
|
-
/**
|
|
213
|
-
* Create a new user with GunDB
|
|
214
|
-
* @param username - Username
|
|
215
|
-
* @param password - Password
|
|
216
|
-
* @returns {Promise<{success: boolean, userPub?: string, error?: string}>} Promise with success status and user public key
|
|
217
|
-
* @description Creates a new user in GunDB with error handling
|
|
218
|
-
*/
|
|
219
|
-
private createUserWithGunDB;
|
|
220
|
-
/**
|
|
221
|
-
* Retrieves data from a Gun node at the specified path
|
|
222
|
-
* @param path - The path to the Gun node
|
|
223
|
-
* @returns Promise that resolves with the node data or rejects with an error
|
|
224
|
-
*/
|
|
225
|
-
get(path: string): Promise<any>;
|
|
226
|
-
/**
|
|
227
|
-
* Stores data in Gun at the root level
|
|
228
|
-
* @param data - The data to store
|
|
229
|
-
* @returns Promise that resolves when data is stored or rejects with an error
|
|
230
|
-
*/
|
|
231
|
-
put(data: Record<string, any>): Promise<any>;
|
|
232
|
-
/**
|
|
233
|
-
* Stores data in the authenticated user's space
|
|
234
|
-
* @param data - The data to store in user space
|
|
235
|
-
* @returns Promise that resolves when data is stored or rejects with an error
|
|
236
|
-
*/
|
|
237
|
-
userPut(data: Record<string, any>): Promise<any>;
|
|
238
|
-
/**
|
|
239
|
-
* Retrieves data from the authenticated user's space at the specified path
|
|
240
|
-
* @param path - The path to the user data
|
|
241
|
-
* @returns Promise that resolves with the user data or rejects with an error
|
|
242
|
-
*/
|
|
243
|
-
userGet(path: string): Promise<any>;
|
|
244
|
-
/**
|
|
245
|
-
* Emits an event through the core's event emitter.
|
|
246
|
-
* Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
|
|
247
|
-
* @param eventName The name of the event to emit.
|
|
248
|
-
* @param data The data to pass with the event.
|
|
249
|
-
*/
|
|
250
|
-
emit(eventName: string | symbol, data?: any): boolean;
|
|
251
|
-
/**
|
|
252
|
-
* Add an event listener
|
|
253
|
-
* @param eventName The name of the event to listen for
|
|
254
|
-
* @param listener The callback function to execute when the event is emitted
|
|
255
|
-
*/
|
|
256
|
-
on(eventName: string | symbol, listener: (data: unknown) => void): this;
|
|
257
|
-
/**
|
|
258
|
-
* Add a one-time event listener
|
|
259
|
-
* @param eventName The name of the event to listen for
|
|
260
|
-
* @param listener The callback function to execute when the event is emitted
|
|
261
|
-
*/
|
|
262
|
-
once(eventName: string | symbol, listener: (data: unknown) => void): this;
|
|
263
|
-
/**
|
|
264
|
-
* Remove an event listener
|
|
265
|
-
* @param eventName The name of the event to stop listening for
|
|
266
|
-
* @param listener The callback function to remove
|
|
267
|
-
*/
|
|
268
|
-
off(eventName: string | symbol, listener: (data: unknown) => void): this;
|
|
269
|
-
/**
|
|
270
|
-
* Remove all listeners for a specific event or all events
|
|
271
|
-
* @param eventName Optional. The name of the event to remove listeners for.
|
|
272
|
-
* If not provided, all listeners for all events are removed.
|
|
273
|
-
*/
|
|
274
|
-
removeAllListeners(eventName?: string | symbol): this;
|
|
275
|
-
}
|
|
276
|
-
export * from "./types/shogun";
|
|
277
|
-
export { GunDB } from "./gun/gun";
|
|
278
|
-
export { MetaMask } from "./plugins/metamask/metamask";
|
|
279
|
-
export { Stealth } from "./plugins/stealth/stealth";
|
|
280
|
-
export type { EphemeralKeyPair, StealthData, StealthAddressResult, LogLevel, LogMessage, } from "./plugins/stealth/types";
|
|
281
|
-
export { Webauthn } from "./plugins/webauthn/webauthn";
|
|
282
|
-
export { ShogunStorage } from "./storage/storage";
|
|
283
|
-
export { ShogunEventEmitter } from "./types/events";
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
export { BasePlugin } from "./base";
|
|
2
2
|
export type { ShogunPlugin, PluginManager } from "../types/plugin";
|
|
3
|
-
export
|
|
4
|
-
export * from "./stealth";
|
|
5
|
-
export * from "./metamask";
|
|
6
|
-
export * from "./webauthn";
|
|
3
|
+
export { Webauthn } from "./webauthn/webauthn";
|
|
7
4
|
export { WebauthnPlugin } from "./webauthn/webauthnPlugin";
|
|
8
5
|
export type { WebauthnPluginInterface } from "./webauthn/types";
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
13
|
-
export {
|
|
14
|
-
export type {
|
|
6
|
+
export { Web3Connector } from "./web3/web3Connector";
|
|
7
|
+
export { Web3ConnectorPlugin } from "./web3/web3ConnectorPlugin";
|
|
8
|
+
export type { Web3ConectorPluginInterface } from "./web3/types";
|
|
9
|
+
export { NostrConnector } from "./nostr/nostrConnector";
|
|
10
|
+
export { NostrConnectorPlugin } from "./nostr/nostrConnectorPlugin";
|
|
11
|
+
export type { NostrConnectorPluginInterface, NostrConnectorCredentials, NostrConnectorKeyPair, NostrConnectorConfig, AlbyProvider, NostrProvider, } from "./nostr/types";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { EventEmitter } from "../../utils/eventEmitter";
|
|
2
|
+
import { ConnectionResult, NostrConnectorCredentials, AlbyProvider, NostrProvider, NostrConnectorConfig, NostrConnectorKeyPair } from "./types";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
alby?: AlbyProvider;
|
|
6
|
+
nostr?: NostrProvider;
|
|
7
|
+
NostrConnector?: typeof NostrConnector;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Class for Bitcoin wallet connections and operations
|
|
12
|
+
*/
|
|
13
|
+
export declare class NostrConnector extends EventEmitter {
|
|
14
|
+
private readonly MESSAGE_TO_SIGN;
|
|
15
|
+
private readonly DEFAULT_CONFIG;
|
|
16
|
+
private readonly config;
|
|
17
|
+
private readonly signatureCache;
|
|
18
|
+
private connectedAddress;
|
|
19
|
+
private connectedType;
|
|
20
|
+
private manualKeyPair;
|
|
21
|
+
constructor(config?: Partial<NostrConnectorConfig>);
|
|
22
|
+
/**
|
|
23
|
+
* Setup event listeners
|
|
24
|
+
*/
|
|
25
|
+
private setupEventListeners;
|
|
26
|
+
/**
|
|
27
|
+
* Cleanup event listeners
|
|
28
|
+
*/
|
|
29
|
+
cleanup(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get cached signature if valid
|
|
32
|
+
*/
|
|
33
|
+
private getCachedSignature;
|
|
34
|
+
/**
|
|
35
|
+
* Cache signature
|
|
36
|
+
*/
|
|
37
|
+
private cacheSignature;
|
|
38
|
+
/**
|
|
39
|
+
* Clear signature cache for a specific address or all addresses
|
|
40
|
+
*/
|
|
41
|
+
clearSignatureCache(address?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Validates that the address is valid
|
|
44
|
+
*/
|
|
45
|
+
private validateAddress;
|
|
46
|
+
/**
|
|
47
|
+
* Check if Alby extension is available
|
|
48
|
+
* @deprecated Alby support is deprecated, use Nostr instead
|
|
49
|
+
*/
|
|
50
|
+
isAlbyAvailable(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Check if Nostr extension is available
|
|
53
|
+
*/
|
|
54
|
+
isNostrExtensionAvailable(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Check if any Bitcoin wallet is available
|
|
57
|
+
*/
|
|
58
|
+
isAvailable(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Connect to a wallet type
|
|
61
|
+
*/
|
|
62
|
+
connectWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Connect to Nostr extension
|
|
65
|
+
*/
|
|
66
|
+
private connectNostr;
|
|
67
|
+
/**
|
|
68
|
+
* Set up manual key pair for connection
|
|
69
|
+
*/
|
|
70
|
+
private connectManual;
|
|
71
|
+
/**
|
|
72
|
+
* Set a manual key pair for use
|
|
73
|
+
*/
|
|
74
|
+
setKeyPair(keyPair: NostrConnectorKeyPair): void;
|
|
75
|
+
/**
|
|
76
|
+
* Generate credentials using the connected wallet
|
|
77
|
+
*/
|
|
78
|
+
generateCredentials(address: string): Promise<NostrConnectorCredentials>;
|
|
79
|
+
/**
|
|
80
|
+
* Generate a deterministic signature for consistent authentication
|
|
81
|
+
*/
|
|
82
|
+
private generateDeterministicSignature;
|
|
83
|
+
/**
|
|
84
|
+
* Generate credentials from an existing signature
|
|
85
|
+
*/
|
|
86
|
+
private generateCredentialsFromSignature;
|
|
87
|
+
/**
|
|
88
|
+
* Generate a password from a signature
|
|
89
|
+
*/
|
|
90
|
+
generatePassword(signature: string): Promise<string>;
|
|
91
|
+
/**
|
|
92
|
+
* Verify a signature
|
|
93
|
+
*/
|
|
94
|
+
verifySignature(message: string, signature: string, address: string): Promise<boolean>;
|
|
95
|
+
/**
|
|
96
|
+
* Get the currently connected address
|
|
97
|
+
*/
|
|
98
|
+
getConnectedAddress(): string | null;
|
|
99
|
+
/**
|
|
100
|
+
* Get the currently connected wallet type
|
|
101
|
+
*/
|
|
102
|
+
getConnectedType(): "alby" | "nostr" | "manual" | null;
|
|
103
|
+
/**
|
|
104
|
+
* Request signature with timeout
|
|
105
|
+
*/
|
|
106
|
+
private requestSignatureWithTimeout;
|
|
107
|
+
/**
|
|
108
|
+
* Request a signature from the connected wallet
|
|
109
|
+
*/
|
|
110
|
+
private requestSignature;
|
|
111
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BasePlugin } from "../base";
|
|
2
|
+
import { ShogunCore } from "../../index";
|
|
3
|
+
import { NostrConnectorCredentials, ConnectionResult, NostrConnectorPluginInterface } from "./types";
|
|
4
|
+
import { AuthResult } from "../../types/shogun";
|
|
5
|
+
/**
|
|
6
|
+
* Plugin for managing Bitcoin wallet functionality in ShogunCore
|
|
7
|
+
* Supports Alby, Nostr extensions, or direct key management
|
|
8
|
+
*/
|
|
9
|
+
export declare class NostrConnectorPlugin extends BasePlugin implements NostrConnectorPluginInterface {
|
|
10
|
+
name: string;
|
|
11
|
+
version: string;
|
|
12
|
+
description: string;
|
|
13
|
+
private bitcoinConnector;
|
|
14
|
+
/**
|
|
15
|
+
* @inheritdoc
|
|
16
|
+
*/
|
|
17
|
+
initialize(core: ShogunCore): void;
|
|
18
|
+
/**
|
|
19
|
+
* @inheritdoc
|
|
20
|
+
*/
|
|
21
|
+
destroy(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Ensure that the Bitcoin wallet module is initialized
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private assertBitcoinConnector;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritdoc
|
|
29
|
+
*/
|
|
30
|
+
isAvailable(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Check if Alby extension is available
|
|
33
|
+
* Note: Alby is deprecated in favor of Nostr
|
|
34
|
+
*/
|
|
35
|
+
isAlbyAvailable(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if Nostr extension is available
|
|
38
|
+
*/
|
|
39
|
+
isNostrExtensionAvailable(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @inheritdoc
|
|
42
|
+
*/
|
|
43
|
+
connectBitcoinWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritdoc
|
|
46
|
+
*/
|
|
47
|
+
generateCredentials(address: string): Promise<NostrConnectorCredentials>;
|
|
48
|
+
/**
|
|
49
|
+
* @inheritdoc
|
|
50
|
+
*/
|
|
51
|
+
cleanup(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Clear signature cache for better user recovery
|
|
54
|
+
* @param address - Optional specific address to clear, or clear all if not provided
|
|
55
|
+
*/
|
|
56
|
+
clearSignatureCache(address?: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritdoc
|
|
59
|
+
*/
|
|
60
|
+
verifySignature(message: string, signature: string, address: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritdoc
|
|
63
|
+
*/
|
|
64
|
+
generatePassword(signature: string): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Login with Bitcoin wallet
|
|
67
|
+
* @param address - Bitcoin address
|
|
68
|
+
* @returns {Promise<AuthResult>} Authentication result
|
|
69
|
+
* @description Authenticates the user using Bitcoin wallet credentials after signature verification
|
|
70
|
+
*/
|
|
71
|
+
login(address: string): Promise<AuthResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Register a new user with Bitcoin wallet
|
|
74
|
+
* @param address - Bitcoin address
|
|
75
|
+
* @returns {Promise<AuthResult>} Registration result
|
|
76
|
+
* @description Creates a new user account with Bitcoin wallet credentials
|
|
77
|
+
*/
|
|
78
|
+
signUp(address: string): Promise<AuthResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience method that matches the interface pattern
|
|
81
|
+
*/
|
|
82
|
+
loginWithBitcoinWallet(address: string): Promise<AuthResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience method that matches the interface pattern
|
|
85
|
+
*/
|
|
86
|
+
signUpWithBitcoinWallet(address: string): Promise<AuthResult>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BaseConfig, BaseResult, BaseCacheEntry } from "../../types/common";
|
|
2
|
+
import { AuthResult } from "../../types/shogun";
|
|
3
|
+
/**
|
|
4
|
+
* Result of connection attempt
|
|
5
|
+
*/
|
|
6
|
+
export interface ConnectionResult extends BaseResult {
|
|
7
|
+
address?: string;
|
|
8
|
+
username?: string;
|
|
9
|
+
randomPassword?: string;
|
|
10
|
+
extensionType?: "alby" | "nostr" | "manual";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Structure for credentials generated via Bitcoin wallet
|
|
14
|
+
*/
|
|
15
|
+
export interface NostrConnectorCredentials {
|
|
16
|
+
/** Generated username based on the address */
|
|
17
|
+
username: string;
|
|
18
|
+
/** Generated password based on the signature */
|
|
19
|
+
password: string;
|
|
20
|
+
/** Original message signed by the user */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Signature provided by the wallet */
|
|
23
|
+
signature: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Alby extension interface
|
|
27
|
+
*/
|
|
28
|
+
export interface AlbyProvider {
|
|
29
|
+
isAlby?: boolean;
|
|
30
|
+
enable: () => Promise<any>;
|
|
31
|
+
signMessage?: (message: string, address?: string) => Promise<string>;
|
|
32
|
+
getPublicKey?: () => Promise<string>;
|
|
33
|
+
getInfo?: () => Promise<any>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Nostr extension interface
|
|
37
|
+
*/
|
|
38
|
+
export interface NostrProvider {
|
|
39
|
+
getPublicKey: () => Promise<string>;
|
|
40
|
+
signEvent: (event: any) => Promise<any>;
|
|
41
|
+
nip04: {
|
|
42
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
43
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Cache entry for signatures
|
|
48
|
+
*/
|
|
49
|
+
export interface SignatureCache extends BaseCacheEntry<string> {
|
|
50
|
+
signature: string;
|
|
51
|
+
address: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Bitcoin wallet configuration options
|
|
55
|
+
*/
|
|
56
|
+
export interface NostrConnectorConfig extends BaseConfig {
|
|
57
|
+
cacheDuration?: number;
|
|
58
|
+
network?: "mainnet" | "testnet";
|
|
59
|
+
useApi?: boolean;
|
|
60
|
+
apiUrl?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Bitcoin Key pair interface
|
|
64
|
+
*/
|
|
65
|
+
export interface NostrConnectorKeyPair {
|
|
66
|
+
privateKey: string;
|
|
67
|
+
publicKey: string;
|
|
68
|
+
address: string;
|
|
69
|
+
type: "legacy" | "segwit" | "taproot" | "nostr";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Interface for the Bitcoin wallet plugin
|
|
73
|
+
*/
|
|
74
|
+
export interface NostrConnectorPluginInterface {
|
|
75
|
+
/**
|
|
76
|
+
* Check if any Bitcoin wallet is available in the browser
|
|
77
|
+
* @returns true if a wallet is available, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
isAvailable(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Connect to a Bitcoin wallet
|
|
82
|
+
* @param type Type of wallet to connect to
|
|
83
|
+
* @returns Promise with the connection result
|
|
84
|
+
*/
|
|
85
|
+
connectBitcoinWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Generate credentials using a Bitcoin wallet
|
|
88
|
+
* @param address Bitcoin address
|
|
89
|
+
* @returns Promise with the generated credentials
|
|
90
|
+
*/
|
|
91
|
+
generateCredentials(address: string): Promise<NostrConnectorCredentials>;
|
|
92
|
+
/**
|
|
93
|
+
* Release resources and clean up event listeners
|
|
94
|
+
*/
|
|
95
|
+
cleanup(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Generate a password based on a signature
|
|
98
|
+
* @param signature Signature
|
|
99
|
+
* @returns Promise with the generated password
|
|
100
|
+
*/
|
|
101
|
+
generatePassword(signature: string): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Verify a signature
|
|
104
|
+
* @param message Signed message
|
|
105
|
+
* @param signature Signature to verify
|
|
106
|
+
* @param address The Bitcoin address that supposedly created the signature
|
|
107
|
+
* @returns Promise that resolves to true if the signature is valid
|
|
108
|
+
*/
|
|
109
|
+
verifySignature(message: string, signature: string, address: string): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Login with Bitcoin wallet
|
|
112
|
+
* @param address Bitcoin address
|
|
113
|
+
* @returns Promise with the operation result
|
|
114
|
+
*/
|
|
115
|
+
login(address: string): Promise<AuthResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Signup with Bitcoin wallet
|
|
118
|
+
* @param address Bitcoin address
|
|
119
|
+
* @returns Promise with the operation result
|
|
120
|
+
*/
|
|
121
|
+
signUp(address: string): Promise<AuthResult>;
|
|
122
|
+
}
|
|
@@ -11,7 +11,7 @@ export interface ConnectionResult extends BaseResult {
|
|
|
11
11
|
/**
|
|
12
12
|
* Structure for credentials generated via MetaMask
|
|
13
13
|
*/
|
|
14
|
-
export interface
|
|
14
|
+
export interface Web3ConnectorCredentials {
|
|
15
15
|
/** Generated username based on the address */
|
|
16
16
|
username: string;
|
|
17
17
|
/** Generated password based on the signature */
|
|
@@ -40,13 +40,13 @@ export interface SignatureCache extends BaseCacheEntry<string> {
|
|
|
40
40
|
/**
|
|
41
41
|
* MetaMask configuration options
|
|
42
42
|
*/
|
|
43
|
-
export interface
|
|
43
|
+
export interface Web3Config extends BaseConfig {
|
|
44
44
|
cacheDuration?: number;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Interfaccia per il plugin MetaMask
|
|
48
48
|
*/
|
|
49
|
-
export interface
|
|
49
|
+
export interface Web3ConectorPluginInterface {
|
|
50
50
|
/**
|
|
51
51
|
* Verifica se MetaMask è disponibile nel browser
|
|
52
52
|
* @returns true se MetaMask è disponibile, false altrimenti
|
|
@@ -62,7 +62,7 @@ export interface MetaMaskPluginInterface {
|
|
|
62
62
|
* @param address Indirizzo Ethereum
|
|
63
63
|
* @returns Promise con le credenziali generate
|
|
64
64
|
*/
|
|
65
|
-
generateCredentials(address: string): Promise<
|
|
65
|
+
generateCredentials(address: string): Promise<Web3ConnectorCredentials>;
|
|
66
66
|
/**
|
|
67
67
|
* Rilascia le risorse e pulisce gli event listener
|
|
68
68
|
*/
|