shogun-core 3.0.13 → 3.0.15
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 +27 -1
- package/dist/browser/shogun-core.js +103157 -84871
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +22 -16
- package/dist/core.js +18 -26
- package/dist/examples/api-test.js +273 -0
- package/dist/examples/simple-api-test.js +89 -0
- package/dist/gundb/api.js +126 -189
- package/dist/gundb/crypto.js +32 -17
- package/dist/gundb/db.js +89 -137
- package/dist/gundb/derive.js +20 -17
- package/dist/gundb/errors.js +17 -7
- package/dist/gundb/index.js +19 -3
- package/dist/gundb/rxjs.js +19 -17
- package/dist/gundb/types.js +2 -1
- package/dist/index.js +43 -12
- package/dist/interfaces/common.js +2 -1
- package/dist/interfaces/events.js +6 -2
- package/dist/interfaces/plugin.js +2 -1
- package/dist/interfaces/shogun.js +7 -4
- package/dist/managers/AuthManager.js +9 -7
- package/dist/managers/CoreInitializer.js +23 -20
- package/dist/managers/EventManager.js +7 -4
- package/dist/managers/PluginManager.js +6 -3
- package/dist/migration-test.js +13 -8
- package/dist/plugins/base.js +11 -8
- package/dist/plugins/index.js +36 -10
- package/dist/plugins/nostr/index.js +20 -4
- package/dist/plugins/nostr/nostrConnector.js +42 -36
- package/dist/plugins/nostr/nostrConnectorPlugin.js +36 -29
- package/dist/plugins/nostr/nostrSigner.js +17 -11
- package/dist/plugins/nostr/types.js +2 -1
- package/dist/plugins/oauth/index.js +7 -2
- package/dist/plugins/oauth/oauthConnector.js +75 -69
- package/dist/plugins/oauth/oauthPlugin.js +31 -27
- package/dist/plugins/oauth/types.js +2 -1
- package/dist/plugins/web3/index.js +20 -4
- package/dist/plugins/web3/types.js +2 -1
- package/dist/plugins/web3/web3Connector.js +38 -33
- package/dist/plugins/web3/web3ConnectorPlugin.js +29 -22
- package/dist/plugins/web3/web3Signer.js +24 -18
- package/dist/plugins/webauthn/index.js +19 -3
- package/dist/plugins/webauthn/types.js +5 -2
- package/dist/plugins/webauthn/webauthn.js +30 -25
- package/dist/plugins/webauthn/webauthnPlugin.js +21 -14
- package/dist/plugins/webauthn/webauthnSigner.js +20 -14
- package/dist/storage/storage.js +5 -4
- package/dist/types/events.js +8 -2
- package/dist/types/examples/api-test.d.ts +12 -0
- package/dist/types/examples/simple-api-test.d.ts +5 -0
- package/dist/types/gundb/api.d.ts +0 -26
- package/dist/types/gundb/db.d.ts +2 -35
- package/dist/types/shogun.js +7 -4
- package/dist/utils/errorHandler.js +13 -8
- package/dist/utils/eventEmitter.js +5 -2
- package/dist/utils/validation.js +14 -7
- package/package.json +2 -1
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OAuthPlugin = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const oauthConnector_1 = require("./oauthConnector");
|
|
6
|
+
const errorHandler_1 = require("../../utils/errorHandler");
|
|
7
|
+
const storage_1 = require("../../storage/storage");
|
|
5
8
|
/**
|
|
6
9
|
* OAuth Plugin for ShogunCore
|
|
7
10
|
* Provides authentication with external OAuth providers
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
name = "oauth";
|
|
11
|
-
version = "1.0.0";
|
|
12
|
-
description = "Provides OAuth authentication with external providers for ShogunCore";
|
|
13
|
-
oauthConnector = null;
|
|
14
|
-
config = {};
|
|
15
|
-
storage = null;
|
|
12
|
+
class OAuthPlugin extends base_1.BasePlugin {
|
|
16
13
|
/**
|
|
17
14
|
* Constructor for OAuthPlugin
|
|
18
15
|
* @param config - Initial configuration for OAuth
|
|
19
16
|
*/
|
|
20
17
|
constructor(config) {
|
|
21
18
|
super();
|
|
19
|
+
this.name = "oauth";
|
|
20
|
+
this.version = "1.0.0";
|
|
21
|
+
this.description = "Provides OAuth authentication with external providers for ShogunCore";
|
|
22
|
+
this.oauthConnector = null;
|
|
23
|
+
this.config = {};
|
|
24
|
+
this.storage = null;
|
|
22
25
|
if (config) {
|
|
23
26
|
this.config = config;
|
|
24
27
|
}
|
|
@@ -28,9 +31,9 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
28
31
|
*/
|
|
29
32
|
initialize(core) {
|
|
30
33
|
this.core = core;
|
|
31
|
-
this.storage = new ShogunStorage();
|
|
34
|
+
this.storage = new storage_1.ShogunStorage();
|
|
32
35
|
// Inizializziamo il connector OAuth con la configurazione già presente
|
|
33
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
36
|
+
this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
|
|
34
37
|
// Valida la configurazione di sicurezza dopo l'inizializzazione
|
|
35
38
|
this.validateOAuthSecurity();
|
|
36
39
|
}
|
|
@@ -75,7 +78,7 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
75
78
|
this.config = { ...this.config, ...config, providers: mergedProviders };
|
|
76
79
|
// Inizializza il connector se non è già stato fatto
|
|
77
80
|
if (!this.oauthConnector) {
|
|
78
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
81
|
+
this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
|
|
79
82
|
}
|
|
80
83
|
else {
|
|
81
84
|
// Update connector configuration se già inizializzato
|
|
@@ -85,7 +88,7 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
85
88
|
}
|
|
86
89
|
else {
|
|
87
90
|
// Fallback: recreate connector
|
|
88
|
-
this.oauthConnector = new OAuthConnector(this.config);
|
|
91
|
+
this.oauthConnector = new oauthConnector_1.OAuthConnector(this.config);
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
// Validate security settings
|
|
@@ -177,20 +180,20 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
177
180
|
try {
|
|
178
181
|
const core = this.assertInitialized();
|
|
179
182
|
if (!provider) {
|
|
180
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth login");
|
|
183
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth login");
|
|
181
184
|
}
|
|
182
185
|
if (!this.isSupported()) {
|
|
183
|
-
throw createError(ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
186
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
184
187
|
}
|
|
185
188
|
// Check if provider is available
|
|
186
189
|
const availableProviders = this.getAvailableProviders();
|
|
187
190
|
if (!availableProviders.includes(provider)) {
|
|
188
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
191
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
189
192
|
}
|
|
190
193
|
// Initiate OAuth flow with the provider
|
|
191
194
|
const oauthResult = await this.initiateOAuth(provider);
|
|
192
195
|
if (!oauthResult.success) {
|
|
193
|
-
throw createError(ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
196
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
194
197
|
}
|
|
195
198
|
// In a browser environment, this would redirect to the OAuth provider
|
|
196
199
|
// The frontend should handle the redirect and then call handleOAuthCallback
|
|
@@ -207,10 +210,10 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
207
210
|
}
|
|
208
211
|
catch (error) {
|
|
209
212
|
// Handle both ShogunError and generic errors
|
|
210
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
213
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
211
214
|
const errorCode = error?.code || "OAUTH_LOGIN_ERROR";
|
|
212
215
|
const errorMessage = error?.message || "Unknown error during OAuth login";
|
|
213
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
216
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
214
217
|
return { success: false, error: errorMessage };
|
|
215
218
|
}
|
|
216
219
|
}
|
|
@@ -223,20 +226,20 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
223
226
|
try {
|
|
224
227
|
const core = this.assertInitialized();
|
|
225
228
|
if (!provider) {
|
|
226
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth signup");
|
|
229
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_REQUIRED", "OAuth provider required for OAuth signup");
|
|
227
230
|
}
|
|
228
231
|
if (!this.isSupported()) {
|
|
229
|
-
throw createError(ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
232
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "OAUTH_UNAVAILABLE", "OAuth is not supported in this environment");
|
|
230
233
|
}
|
|
231
234
|
// Check if provider is available
|
|
232
235
|
const availableProviders = this.getAvailableProviders();
|
|
233
236
|
if (!availableProviders.includes(provider)) {
|
|
234
|
-
throw createError(ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
237
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "PROVIDER_NOT_CONFIGURED", `Provider ${provider} is not configured or available`);
|
|
235
238
|
}
|
|
236
239
|
// Initiate OAuth flow with the provider
|
|
237
240
|
const oauthResult = await this.initiateOAuth(provider);
|
|
238
241
|
if (!oauthResult.success) {
|
|
239
|
-
throw createError(ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
242
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "OAUTH_INITIATION_FAILED", oauthResult.error || "Failed to initiate OAuth flow");
|
|
240
243
|
}
|
|
241
244
|
// In a browser environment, this would redirect to the OAuth provider
|
|
242
245
|
// The frontend should handle the redirect and then call handleOAuthCallback
|
|
@@ -253,10 +256,10 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
253
256
|
}
|
|
254
257
|
catch (error) {
|
|
255
258
|
// Handle both ShogunError and generic errors
|
|
256
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
259
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
257
260
|
const errorCode = error?.code || "OAUTH_SIGNUP_ERROR";
|
|
258
261
|
const errorMessage = error?.message || "Unknown error during OAuth signup";
|
|
259
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
262
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
260
263
|
return { success: false, error: errorMessage };
|
|
261
264
|
}
|
|
262
265
|
}
|
|
@@ -394,3 +397,4 @@ export class OAuthPlugin extends BasePlugin {
|
|
|
394
397
|
return signupResult;
|
|
395
398
|
}
|
|
396
399
|
}
|
|
400
|
+
exports.OAuthPlugin = OAuthPlugin;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./web3ConnectorPlugin"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./web3Connector"), exports);
|
|
20
|
+
__exportStar(require("./web3Signer"), exports);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Web3Connector = void 0;
|
|
1
7
|
/**
|
|
2
8
|
* The MetaMaskAuth class provides functionality for connecting, signing up, and logging in using MetaMask.
|
|
3
9
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const errorHandler_1 = require("../../utils/errorHandler");
|
|
12
|
+
const eventEmitter_1 = require("../../utils/eventEmitter");
|
|
13
|
+
const derive_1 = __importDefault(require("../../gundb/derive"));
|
|
8
14
|
/**
|
|
9
15
|
* Class for MetaMask connection
|
|
10
16
|
*/
|
|
11
|
-
class Web3Connector extends EventEmitter {
|
|
12
|
-
MESSAGE_TO_SIGN = "I Love Shogun!";
|
|
13
|
-
DEFAULT_CONFIG = {
|
|
14
|
-
cacheDuration: 30 * 60 * 1000, // 30 minutes
|
|
15
|
-
maxRetries: 3,
|
|
16
|
-
retryDelay: 1000,
|
|
17
|
-
timeout: 60000,
|
|
18
|
-
};
|
|
19
|
-
config;
|
|
20
|
-
signatureCache = new Map();
|
|
21
|
-
provider = null;
|
|
22
|
-
customProvider = null;
|
|
23
|
-
customWallet = null;
|
|
17
|
+
class Web3Connector extends eventEmitter_1.EventEmitter {
|
|
24
18
|
constructor(config = {}) {
|
|
25
19
|
super();
|
|
20
|
+
this.MESSAGE_TO_SIGN = "I Love Shogun!";
|
|
21
|
+
this.DEFAULT_CONFIG = {
|
|
22
|
+
cacheDuration: 30 * 60 * 1000, // 30 minutes
|
|
23
|
+
maxRetries: 3,
|
|
24
|
+
retryDelay: 1000,
|
|
25
|
+
timeout: 60000,
|
|
26
|
+
};
|
|
27
|
+
this.signatureCache = new Map();
|
|
28
|
+
this.provider = null;
|
|
29
|
+
this.customProvider = null;
|
|
30
|
+
this.customWallet = null;
|
|
26
31
|
this.config = { ...this.DEFAULT_CONFIG, ...config };
|
|
27
32
|
this.initProvider();
|
|
28
33
|
this.setupEventListeners();
|
|
@@ -37,7 +42,7 @@ class Web3Connector extends EventEmitter {
|
|
|
37
42
|
// Check if ethereum is available from any provider
|
|
38
43
|
const ethereumProvider = this.getAvailableEthereumProvider();
|
|
39
44
|
if (ethereumProvider) {
|
|
40
|
-
this.provider = new ethers.BrowserProvider(ethereumProvider);
|
|
45
|
+
this.provider = new ethers_1.ethers.BrowserProvider(ethereumProvider);
|
|
41
46
|
}
|
|
42
47
|
else {
|
|
43
48
|
console.warn("No compatible Ethereum provider found");
|
|
@@ -123,7 +128,7 @@ class Web3Connector extends EventEmitter {
|
|
|
123
128
|
// Check if ethereum is available from any provider
|
|
124
129
|
const ethereumProvider = this.getAvailableEthereumProvider();
|
|
125
130
|
if (ethereumProvider) {
|
|
126
|
-
this.provider = new ethers.BrowserProvider(ethereumProvider);
|
|
131
|
+
this.provider = new ethers_1.ethers.BrowserProvider(ethereumProvider);
|
|
127
132
|
}
|
|
128
133
|
else {
|
|
129
134
|
console.warn("No compatible Ethereum provider found");
|
|
@@ -214,13 +219,13 @@ class Web3Connector extends EventEmitter {
|
|
|
214
219
|
}
|
|
215
220
|
try {
|
|
216
221
|
const normalizedAddress = String(address).trim().toLowerCase();
|
|
217
|
-
if (!ethers.isAddress(normalizedAddress)) {
|
|
222
|
+
if (!ethers_1.ethers.isAddress(normalizedAddress)) {
|
|
218
223
|
throw new Error("Invalid address format");
|
|
219
224
|
}
|
|
220
|
-
return ethers.getAddress(normalizedAddress);
|
|
225
|
+
return ethers_1.ethers.getAddress(normalizedAddress);
|
|
221
226
|
}
|
|
222
227
|
catch (error) {
|
|
223
|
-
ErrorHandler.handle(ErrorType.VALIDATION, "INVALID_ADDRESS", "Invalid Ethereum address provided", error);
|
|
228
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.VALIDATION, "INVALID_ADDRESS", "Invalid Ethereum address provided", error);
|
|
224
229
|
throw error;
|
|
225
230
|
}
|
|
226
231
|
}
|
|
@@ -296,7 +301,7 @@ class Web3Connector extends EventEmitter {
|
|
|
296
301
|
}
|
|
297
302
|
catch (error) {
|
|
298
303
|
console.error("Failed to connect to MetaMask:", error);
|
|
299
|
-
ErrorHandler.handle(ErrorType.WEBAUTHN, "METAMASK_CONNECTION_ERROR", error.message ?? "Unknown error while connecting to MetaMask", error);
|
|
304
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "METAMASK_CONNECTION_ERROR", error.message ?? "Unknown error while connecting to MetaMask", error);
|
|
300
305
|
return { success: false, error: error.message };
|
|
301
306
|
}
|
|
302
307
|
}
|
|
@@ -326,7 +331,7 @@ class Web3Connector extends EventEmitter {
|
|
|
326
331
|
return this.generateCredentialsFromSignature(validAddress, signature);
|
|
327
332
|
}
|
|
328
333
|
catch (error) {
|
|
329
|
-
ErrorHandler.handle(ErrorType.WEBAUTHN, "CREDENTIALS_GENERATION_ERROR", error.message ?? "Error generating MetaMask credentials", error);
|
|
334
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.WEBAUTHN, "CREDENTIALS_GENERATION_ERROR", error.message ?? "Error generating MetaMask credentials", error);
|
|
330
335
|
throw error;
|
|
331
336
|
}
|
|
332
337
|
}
|
|
@@ -334,9 +339,9 @@ class Web3Connector extends EventEmitter {
|
|
|
334
339
|
* Generates credentials from a signature
|
|
335
340
|
*/
|
|
336
341
|
async generateCredentialsFromSignature(address, signature) {
|
|
337
|
-
const hashedAddress = ethers.keccak256(ethers.toUtf8Bytes(address));
|
|
342
|
+
const hashedAddress = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(address));
|
|
338
343
|
const salt = `${address}_${signature}`;
|
|
339
|
-
return await
|
|
344
|
+
return await (0, derive_1.default)(hashedAddress, salt, {
|
|
340
345
|
includeP256: true,
|
|
341
346
|
});
|
|
342
347
|
}
|
|
@@ -346,7 +351,7 @@ class Web3Connector extends EventEmitter {
|
|
|
346
351
|
generateFallbackCredentials(address) {
|
|
347
352
|
console.warn("Using fallback credentials generation for address:", address);
|
|
348
353
|
// Generate a deterministic but insecure fallback
|
|
349
|
-
const fallbackSignature = ethers.keccak256(ethers.toUtf8Bytes(address + "fallback"));
|
|
354
|
+
const fallbackSignature = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(address + "fallback"));
|
|
350
355
|
return {
|
|
351
356
|
username: address.toLowerCase(),
|
|
352
357
|
password: fallbackSignature,
|
|
@@ -427,8 +432,8 @@ class Web3Connector extends EventEmitter {
|
|
|
427
432
|
*/
|
|
428
433
|
setCustomProvider(rpcUrl, privateKey) {
|
|
429
434
|
try {
|
|
430
|
-
this.customProvider = new ethers.JsonRpcProvider(rpcUrl);
|
|
431
|
-
this.customWallet = new ethers.Wallet(privateKey, this.customProvider);
|
|
435
|
+
this.customProvider = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
|
|
436
|
+
this.customWallet = new ethers_1.ethers.Wallet(privateKey, this.customProvider);
|
|
432
437
|
}
|
|
433
438
|
catch (error) {
|
|
434
439
|
throw new Error(`Error configuring provider: ${error.message ?? "Unknown error"}`);
|
|
@@ -476,7 +481,7 @@ class Web3Connector extends EventEmitter {
|
|
|
476
481
|
if (!signature) {
|
|
477
482
|
throw new Error("Invalid signature");
|
|
478
483
|
}
|
|
479
|
-
const hash = ethers.keccak256(ethers.toUtf8Bytes(signature));
|
|
484
|
+
const hash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(signature));
|
|
480
485
|
return hash.slice(2, 66); // Remove 0x and use first 32 bytes
|
|
481
486
|
}
|
|
482
487
|
/**
|
|
@@ -491,7 +496,7 @@ class Web3Connector extends EventEmitter {
|
|
|
491
496
|
throw new Error("Invalid message or signature");
|
|
492
497
|
}
|
|
493
498
|
try {
|
|
494
|
-
return ethers.verifyMessage(message, signature);
|
|
499
|
+
return ethers_1.ethers.verifyMessage(message, signature);
|
|
495
500
|
}
|
|
496
501
|
catch (error) {
|
|
497
502
|
throw new Error("Invalid message or signature");
|
|
@@ -511,7 +516,7 @@ class Web3Connector extends EventEmitter {
|
|
|
511
516
|
await ethereum.request({
|
|
512
517
|
method: "eth_requestAccounts",
|
|
513
518
|
});
|
|
514
|
-
const provider = new ethers.BrowserProvider(ethereum);
|
|
519
|
+
const provider = new ethers_1.ethers.BrowserProvider(ethereum);
|
|
515
520
|
return provider.getSigner();
|
|
516
521
|
}
|
|
517
522
|
catch (error) {
|
|
@@ -519,10 +524,10 @@ class Web3Connector extends EventEmitter {
|
|
|
519
524
|
}
|
|
520
525
|
}
|
|
521
526
|
}
|
|
527
|
+
exports.Web3Connector = Web3Connector;
|
|
522
528
|
if (typeof window !== "undefined") {
|
|
523
529
|
window.Web3Connector = Web3Connector;
|
|
524
530
|
}
|
|
525
531
|
else if (typeof global !== "undefined") {
|
|
526
532
|
global.Web3Connector = Web3Connector;
|
|
527
533
|
}
|
|
528
|
-
export { Web3Connector };
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Web3ConnectorPlugin = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const web3Connector_1 = require("./web3Connector");
|
|
6
|
+
const web3Signer_1 = require("./web3Signer");
|
|
7
|
+
const errorHandler_1 = require("../../utils/errorHandler");
|
|
5
8
|
/**
|
|
6
9
|
* Plugin per la gestione delle funzionalità Web3 in ShogunCore
|
|
7
10
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
class Web3ConnectorPlugin extends base_1.BasePlugin {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.name = "web3";
|
|
15
|
+
this.version = "1.0.0";
|
|
16
|
+
this.description = "Provides Ethereum wallet connection and authentication for ShogunCore";
|
|
17
|
+
this.Web3 = null;
|
|
18
|
+
this.signer = null;
|
|
19
|
+
}
|
|
14
20
|
/**
|
|
15
21
|
* @inheritdoc
|
|
16
22
|
*/
|
|
17
23
|
initialize(core) {
|
|
18
24
|
super.initialize(core);
|
|
19
25
|
// Inizializziamo il modulo Web3
|
|
20
|
-
this.Web3 = new Web3Connector();
|
|
21
|
-
this.signer = new Web3Signer(this.Web3);
|
|
26
|
+
this.Web3 = new web3Connector_1.Web3Connector();
|
|
27
|
+
this.signer = new web3Signer_1.Web3Signer(this.Web3);
|
|
22
28
|
// Rimuovo i console.log superflui
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
@@ -316,10 +322,10 @@ export class Web3ConnectorPlugin extends BasePlugin {
|
|
|
316
322
|
try {
|
|
317
323
|
const core = this.assertInitialized();
|
|
318
324
|
if (!address) {
|
|
319
|
-
throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 login");
|
|
325
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 login");
|
|
320
326
|
}
|
|
321
327
|
if (!this.isAvailable()) {
|
|
322
|
-
throw createError(ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
|
|
328
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
|
|
323
329
|
}
|
|
324
330
|
console.log(`🔧 Web3 login - starting login for address:`, address);
|
|
325
331
|
// FIX: Use deterministic pair instead of generating new credentials
|
|
@@ -366,7 +372,7 @@ export class Web3ConnectorPlugin extends BasePlugin {
|
|
|
366
372
|
address,
|
|
367
373
|
});
|
|
368
374
|
if (!gunUser.success) {
|
|
369
|
-
throw createError(ErrorType.AUTHENTICATION, "WEB3_LOGIN_FAILED", gunUser.error || "Failed to log in with Web3 credentials");
|
|
375
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "WEB3_LOGIN_FAILED", gunUser.error || "Failed to log in with Web3 credentials");
|
|
370
376
|
}
|
|
371
377
|
console.log(`🔧 Web3 login - gunUser success, userPub:`, gunUser.userPub ? gunUser.userPub.slice(0, 8) + "..." : "null");
|
|
372
378
|
// Set authentication method to web3
|
|
@@ -397,10 +403,10 @@ export class Web3ConnectorPlugin extends BasePlugin {
|
|
|
397
403
|
}
|
|
398
404
|
catch (error) {
|
|
399
405
|
// Handle both ShogunError and generic errors
|
|
400
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
406
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
401
407
|
const errorCode = error?.code || "WEB3_LOGIN_ERROR";
|
|
402
408
|
const errorMessage = error?.message || "Unknown error during Web3 login";
|
|
403
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
409
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
404
410
|
return { success: false, error: errorMessage };
|
|
405
411
|
}
|
|
406
412
|
}
|
|
@@ -413,15 +419,15 @@ export class Web3ConnectorPlugin extends BasePlugin {
|
|
|
413
419
|
try {
|
|
414
420
|
const core = this.assertInitialized();
|
|
415
421
|
if (!address) {
|
|
416
|
-
throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 registration");
|
|
422
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Ethereum address required for Web3 registration");
|
|
417
423
|
}
|
|
418
424
|
if (!this.isAvailable()) {
|
|
419
|
-
throw createError(ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
|
|
425
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "WEB3_UNAVAILABLE", "Web3 is not available in the browser");
|
|
420
426
|
}
|
|
421
427
|
// Use setupConsistentOneshotSigning for signup
|
|
422
428
|
const { gunUser } = await this.setupConsistentOneshotSigning(address);
|
|
423
429
|
if (!gunUser.success) {
|
|
424
|
-
throw createError(ErrorType.AUTHENTICATION, "WEB3_SIGNUP_FAILED", gunUser.error || "Failed to sign up with Web3 credentials");
|
|
430
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "WEB3_SIGNUP_FAILED", gunUser.error || "Failed to sign up with Web3 credentials");
|
|
425
431
|
}
|
|
426
432
|
// Set authentication method to web3
|
|
427
433
|
core.setAuthMethod("web3");
|
|
@@ -438,11 +444,12 @@ export class Web3ConnectorPlugin extends BasePlugin {
|
|
|
438
444
|
}
|
|
439
445
|
catch (error) {
|
|
440
446
|
// Handle both ShogunError and generic errors
|
|
441
|
-
const errorType = error?.type || ErrorType.AUTHENTICATION;
|
|
447
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
442
448
|
const errorCode = error?.code || "WEB3_SIGNUP_ERROR";
|
|
443
449
|
const errorMessage = error?.message || "Unknown error during Web3 registration";
|
|
444
|
-
ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
450
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
445
451
|
return { success: false, error: errorMessage };
|
|
446
452
|
}
|
|
447
453
|
}
|
|
448
454
|
}
|
|
455
|
+
exports.Web3ConnectorPlugin = Web3ConnectorPlugin;
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Web3Signer = void 0;
|
|
7
|
+
const web3Connector_1 = require("./web3Connector");
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const derive_1 = __importDefault(require("../../gundb/derive"));
|
|
4
10
|
/**
|
|
5
11
|
* Web3 Signer - Provides oneshot signing functionality
|
|
6
12
|
* Similar to webauthn.js but for Web3/MetaMask
|
|
7
13
|
* CONSISTENT with normal Web3 approach
|
|
8
14
|
*/
|
|
9
|
-
|
|
10
|
-
web3Connector;
|
|
11
|
-
credentials = new Map();
|
|
12
|
-
MESSAGE_TO_SIGN = "I Love Shogun!"; // Same as normal approach
|
|
15
|
+
class Web3Signer {
|
|
13
16
|
constructor(web3Connector) {
|
|
14
|
-
this.
|
|
17
|
+
this.credentials = new Map();
|
|
18
|
+
this.MESSAGE_TO_SIGN = "I Love Shogun!"; // Same as normal approach
|
|
19
|
+
this.web3Connector = web3Connector || new web3Connector_1.Web3Connector();
|
|
15
20
|
}
|
|
16
21
|
/**
|
|
17
22
|
* Creates a new Web3 signing credential
|
|
@@ -20,14 +25,14 @@ export class Web3Signer {
|
|
|
20
25
|
async createSigningCredential(address) {
|
|
21
26
|
try {
|
|
22
27
|
// Validate address
|
|
23
|
-
const validAddress = ethers.getAddress(address.toLowerCase());
|
|
28
|
+
const validAddress = ethers_1.ethers.getAddress(address.toLowerCase());
|
|
24
29
|
// Request signature using the same approach as normal Web3
|
|
25
30
|
const signature = await this.requestSignature(validAddress);
|
|
26
31
|
// Generate credentials using the SAME logic as normal approach
|
|
27
32
|
const username = `${validAddress.toLowerCase()}`;
|
|
28
33
|
// FIX: Use only address for password generation to ensure consistency
|
|
29
34
|
// The signature changes each time, causing different passwords for same user
|
|
30
|
-
const password = ethers.keccak256(ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
35
|
+
const password = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
31
36
|
const signingCredential = {
|
|
32
37
|
address: validAddress,
|
|
33
38
|
signature,
|
|
@@ -137,11 +142,11 @@ export class Web3Signer {
|
|
|
137
142
|
async createDerivedKeyPairFromAddress(address, extra) {
|
|
138
143
|
try {
|
|
139
144
|
// Generate deterministic password from address (same as createSigningCredential)
|
|
140
|
-
const validAddress = ethers.getAddress(address.toLowerCase());
|
|
141
|
-
const password = ethers.keccak256(ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
145
|
+
const validAddress = ethers_1.ethers.getAddress(address.toLowerCase());
|
|
146
|
+
const password = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
142
147
|
console.log(`🔧 Web3Signer - generating deterministic pair for address:`, validAddress);
|
|
143
148
|
// Use the same derive function as normal approach
|
|
144
|
-
const derivedKeys = await
|
|
149
|
+
const derivedKeys = await (0, derive_1.default)(password, // Deterministic password from address
|
|
145
150
|
extra, { includeP256: true });
|
|
146
151
|
return {
|
|
147
152
|
pub: derivedKeys.pub,
|
|
@@ -220,9 +225,9 @@ export class Web3Signer {
|
|
|
220
225
|
const keyPair = await this.createDerivedKeyPair(address, extra);
|
|
221
226
|
// Create signature using the same approach as SEA
|
|
222
227
|
const message = JSON.stringify(data);
|
|
223
|
-
const messageHash = ethers.keccak256(ethers.toUtf8Bytes(message));
|
|
228
|
+
const messageHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(message));
|
|
224
229
|
// Use ethers for signing (compatible with SEA)
|
|
225
|
-
const wallet = new ethers.Wallet(keyPair.priv);
|
|
230
|
+
const wallet = new ethers_1.ethers.Wallet(keyPair.priv);
|
|
226
231
|
const signature = await wallet.signMessage(message);
|
|
227
232
|
// Format like SEA signature
|
|
228
233
|
const seaSignature = {
|
|
@@ -257,8 +262,8 @@ export class Web3Signer {
|
|
|
257
262
|
getPassword(address) {
|
|
258
263
|
try {
|
|
259
264
|
// Generate deterministic password from address (same as createSigningCredential)
|
|
260
|
-
const validAddress = ethers.getAddress(address.toLowerCase());
|
|
261
|
-
const password = ethers.keccak256(ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
265
|
+
const validAddress = ethers_1.ethers.getAddress(address.toLowerCase());
|
|
266
|
+
const password = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`${validAddress.toLowerCase()}:shogun-web3`));
|
|
262
267
|
return password;
|
|
263
268
|
}
|
|
264
269
|
catch (error) {
|
|
@@ -305,4 +310,5 @@ export class Web3Signer {
|
|
|
305
310
|
return this.credentials.delete(address.toLowerCase());
|
|
306
311
|
}
|
|
307
312
|
}
|
|
308
|
-
|
|
313
|
+
exports.Web3Signer = Web3Signer;
|
|
314
|
+
exports.default = Web3Signer;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./webauthnPlugin"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./webauthn"), exports);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebAuthnEventType = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* WebAuthn event types
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
var WebAuthnEventType;
|
|
5
8
|
(function (WebAuthnEventType) {
|
|
6
9
|
WebAuthnEventType["DEVICE_REGISTERED"] = "deviceRegistered";
|
|
7
10
|
WebAuthnEventType["DEVICE_REMOVED"] = "deviceRemoved";
|
|
8
11
|
WebAuthnEventType["AUTHENTICATION_SUCCESS"] = "authenticationSuccess";
|
|
9
12
|
WebAuthnEventType["AUTHENTICATION_FAILED"] = "authenticationFailed";
|
|
10
13
|
WebAuthnEventType["ERROR"] = "error";
|
|
11
|
-
})(WebAuthnEventType || (WebAuthnEventType = {}));
|
|
14
|
+
})(WebAuthnEventType || (exports.WebAuthnEventType = WebAuthnEventType = {}));
|