shogun-core 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/browser/shogun-core.js +0 -92128
- package/dist/browser/shogun-core.js.map +0 -1
- package/dist/config/simplified-config.js +0 -230
- package/dist/core.js +0 -338
- package/dist/gundb/crypto.js +0 -268
- package/dist/gundb/db.js +0 -1833
- package/dist/gundb/derive.js +0 -229
- package/dist/gundb/errors.js +0 -66
- package/dist/gundb/index.js +0 -6
- package/dist/gundb/restricted-put.js +0 -81
- package/dist/gundb/rxjs.js +0 -445
- package/dist/gundb/simple-api.js +0 -438
- package/dist/gundb/types.js +0 -4
- package/dist/index.js +0 -16
- package/dist/interfaces/common.js +0 -1
- package/dist/interfaces/events.js +0 -36
- package/dist/interfaces/plugin.js +0 -1
- package/dist/interfaces/shogun.js +0 -34
- package/dist/managers/AuthManager.js +0 -225
- package/dist/managers/CoreInitializer.js +0 -234
- package/dist/managers/EventManager.js +0 -67
- package/dist/managers/PluginManager.js +0 -296
- package/dist/migration-test.js +0 -91
- package/dist/plugins/base.js +0 -47
- package/dist/plugins/index.js +0 -15
- package/dist/plugins/nostr/index.js +0 -4
- package/dist/plugins/nostr/nostrConnector.js +0 -413
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -446
- package/dist/plugins/nostr/nostrSigner.js +0 -313
- package/dist/plugins/nostr/types.js +0 -1
- package/dist/plugins/oauth/index.js +0 -3
- package/dist/plugins/oauth/oauthConnector.js +0 -753
- package/dist/plugins/oauth/oauthPlugin.js +0 -396
- package/dist/plugins/oauth/types.js +0 -1
- package/dist/plugins/web3/index.js +0 -4
- package/dist/plugins/web3/types.js +0 -1
- package/dist/plugins/web3/web3Connector.js +0 -528
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -448
- package/dist/plugins/web3/web3Signer.js +0 -308
- package/dist/plugins/webauthn/index.js +0 -3
- package/dist/plugins/webauthn/types.js +0 -11
- package/dist/plugins/webauthn/webauthn.js +0 -478
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -398
- package/dist/plugins/webauthn/webauthnSigner.js +0 -304
- package/dist/storage/storage.js +0 -147
- package/dist/types/config/simplified-config.d.ts +0 -114
- package/dist/types/core.d.ts +0 -305
- package/dist/types/gundb/crypto.d.ts +0 -95
- package/dist/types/gundb/db.d.ts +0 -404
- package/dist/types/gundb/derive.d.ts +0 -21
- package/dist/types/gundb/errors.d.ts +0 -42
- package/dist/types/gundb/index.d.ts +0 -3
- package/dist/types/gundb/restricted-put.d.ts +0 -15
- package/dist/types/gundb/rxjs.d.ts +0 -110
- package/dist/types/gundb/simple-api.d.ts +0 -90
- package/dist/types/gundb/types.d.ts +0 -264
- package/dist/types/index.d.ts +0 -14
- package/dist/types/interfaces/common.d.ts +0 -85
- package/dist/types/interfaces/events.d.ts +0 -131
- package/dist/types/interfaces/plugin.d.ts +0 -162
- package/dist/types/interfaces/shogun.d.ts +0 -215
- package/dist/types/managers/AuthManager.d.ts +0 -72
- package/dist/types/managers/CoreInitializer.d.ts +0 -40
- package/dist/types/managers/EventManager.d.ts +0 -49
- package/dist/types/managers/PluginManager.d.ts +0 -145
- package/dist/types/migration-test.d.ts +0 -16
- package/dist/types/plugins/base.d.ts +0 -35
- package/dist/types/plugins/index.d.ts +0 -14
- package/dist/types/plugins/nostr/index.d.ts +0 -4
- package/dist/types/plugins/nostr/nostrConnector.d.ts +0 -119
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +0 -163
- package/dist/types/plugins/nostr/nostrSigner.d.ts +0 -105
- package/dist/types/plugins/nostr/types.d.ts +0 -122
- package/dist/types/plugins/oauth/index.d.ts +0 -3
- package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
- package/dist/types/plugins/oauth/types.d.ts +0 -114
- package/dist/types/plugins/web3/index.d.ts +0 -4
- package/dist/types/plugins/web3/types.d.ts +0 -107
- package/dist/types/plugins/web3/web3Connector.d.ts +0 -129
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +0 -160
- package/dist/types/plugins/web3/web3Signer.d.ts +0 -114
- package/dist/types/plugins/webauthn/index.d.ts +0 -3
- package/dist/types/plugins/webauthn/types.d.ts +0 -162
- package/dist/types/plugins/webauthn/webauthn.d.ts +0 -129
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +0 -158
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +0 -91
- package/dist/types/storage/storage.d.ts +0 -50
- package/dist/types/utils/errorHandler.d.ts +0 -119
- package/dist/types/utils/eventEmitter.d.ts +0 -39
- package/dist/types/utils/validation.d.ts +0 -27
- package/dist/utils/errorHandler.js +0 -241
- package/dist/utils/eventEmitter.js +0 -76
- package/dist/utils/validation.js +0 -72
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { BasePlugin } from "../base";
|
|
2
|
-
import { ShogunCore } from "../../core";
|
|
3
|
-
import { OAuthPluginInterface, OAuthConfig, OAuthProvider, OAuthConnectionResult, OAuthCredentials, OAuthUserInfo } from "./types";
|
|
4
|
-
import { AuthResult, SignUpResult } from "../../interfaces/shogun";
|
|
5
|
-
/**
|
|
6
|
-
* OAuth Plugin for ShogunCore
|
|
7
|
-
* Provides authentication with external OAuth providers
|
|
8
|
-
*/
|
|
9
|
-
export declare class OAuthPlugin extends BasePlugin implements OAuthPluginInterface {
|
|
10
|
-
name: string;
|
|
11
|
-
version: string;
|
|
12
|
-
description: string;
|
|
13
|
-
private oauthConnector;
|
|
14
|
-
private config;
|
|
15
|
-
private storage;
|
|
16
|
-
/**
|
|
17
|
-
* Constructor for OAuthPlugin
|
|
18
|
-
* @param config - Initial configuration for OAuth
|
|
19
|
-
*/
|
|
20
|
-
constructor(config?: Partial<OAuthConfig>);
|
|
21
|
-
/**
|
|
22
|
-
* @inheritdoc
|
|
23
|
-
*/
|
|
24
|
-
initialize(core: ShogunCore): void;
|
|
25
|
-
/**
|
|
26
|
-
* Valida la configurazione di sicurezza OAuth
|
|
27
|
-
*/
|
|
28
|
-
private validateOAuthSecurity;
|
|
29
|
-
/**
|
|
30
|
-
* Configure the OAuth plugin with provider settings
|
|
31
|
-
* @param config - Configuration options for OAuth
|
|
32
|
-
*/
|
|
33
|
-
configure(config: Partial<OAuthConfig>): void;
|
|
34
|
-
/**
|
|
35
|
-
* @inheritdoc
|
|
36
|
-
*/
|
|
37
|
-
destroy(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Ensure that the OAuth connector is initialized
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
42
|
-
private assertOAuthConnector;
|
|
43
|
-
/**
|
|
44
|
-
* @inheritdoc
|
|
45
|
-
*/
|
|
46
|
-
isSupported(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* @inheritdoc
|
|
49
|
-
*/
|
|
50
|
-
getAvailableProviders(): OAuthProvider[];
|
|
51
|
-
/**
|
|
52
|
-
* @inheritdoc
|
|
53
|
-
*/
|
|
54
|
-
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
55
|
-
/**
|
|
56
|
-
* @inheritdoc
|
|
57
|
-
*/
|
|
58
|
-
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
59
|
-
/**
|
|
60
|
-
* @inheritdoc
|
|
61
|
-
*/
|
|
62
|
-
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
|
|
63
|
-
/**
|
|
64
|
-
* Login with OAuth
|
|
65
|
-
* @param provider - OAuth provider to use
|
|
66
|
-
* @returns {Promise<AuthResult>} Authentication result
|
|
67
|
-
* @description Authenticates user using OAuth with external providers
|
|
68
|
-
* NOTE: This method only initiates the OAuth flow. The actual authentication
|
|
69
|
-
* happens in handleOAuthCallback when the provider redirects back.
|
|
70
|
-
*/
|
|
71
|
-
login(provider: OAuthProvider): Promise<AuthResult>;
|
|
72
|
-
/**
|
|
73
|
-
* Register new user with OAuth provider
|
|
74
|
-
* @param provider - OAuth provider
|
|
75
|
-
* @returns {Promise<SignUpResult>} Registration result
|
|
76
|
-
*/
|
|
77
|
-
signUp(provider: OAuthProvider): Promise<SignUpResult>;
|
|
78
|
-
/**
|
|
79
|
-
* Handle OAuth callback (for frontend integration)
|
|
80
|
-
* This method would be called when the OAuth provider redirects back
|
|
81
|
-
*/
|
|
82
|
-
handleOAuthCallback(provider: OAuthProvider, authCode: string, state: string): Promise<AuthResult>;
|
|
83
|
-
/**
|
|
84
|
-
* Pulisce i dati OAuth scaduti
|
|
85
|
-
*/
|
|
86
|
-
private cleanupExpiredOAuthData;
|
|
87
|
-
/**
|
|
88
|
-
* Private helper to login or sign up a user
|
|
89
|
-
*/
|
|
90
|
-
private _loginOrSignUp;
|
|
91
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { BaseConfig, BaseResult, BaseCacheEntry } from "../../interfaces/common";
|
|
2
|
-
import { AuthResult, SignUpResult } from "../../interfaces/shogun";
|
|
3
|
-
/**
|
|
4
|
-
* Supported OAuth providers
|
|
5
|
-
*/
|
|
6
|
-
export type OAuthProvider = "google" | "github" | "discord" | "twitter" | "custom";
|
|
7
|
-
/**
|
|
8
|
-
* OAuth provider configuration
|
|
9
|
-
*/
|
|
10
|
-
export interface OAuthProviderConfig {
|
|
11
|
-
clientId: string;
|
|
12
|
-
clientSecret?: string;
|
|
13
|
-
redirectUri: string;
|
|
14
|
-
scope: string[];
|
|
15
|
-
authUrl: string;
|
|
16
|
-
tokenUrl: string;
|
|
17
|
-
userInfoUrl: string;
|
|
18
|
-
usePKCE?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* OAuth configuration
|
|
22
|
-
*/
|
|
23
|
-
export interface OAuthConfig extends BaseConfig {
|
|
24
|
-
providers: Partial<Record<OAuthProvider, OAuthProviderConfig>>;
|
|
25
|
-
usePKCE?: boolean;
|
|
26
|
-
cacheDuration?: number;
|
|
27
|
-
timeout?: number;
|
|
28
|
-
maxRetries?: number;
|
|
29
|
-
retryDelay?: number;
|
|
30
|
-
allowUnsafeClientSecret?: boolean;
|
|
31
|
-
stateTimeout?: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* OAuth token response
|
|
35
|
-
*/
|
|
36
|
-
export interface OAuthTokenResponse {
|
|
37
|
-
access_token: string;
|
|
38
|
-
token_type: string;
|
|
39
|
-
expires_in: number;
|
|
40
|
-
refresh_token?: string;
|
|
41
|
-
scope?: string;
|
|
42
|
-
id_token?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* User info from OAuth provider
|
|
46
|
-
*/
|
|
47
|
-
export interface OAuthUserInfo {
|
|
48
|
-
id: string;
|
|
49
|
-
email?: string;
|
|
50
|
-
name?: string;
|
|
51
|
-
picture?: string;
|
|
52
|
-
verified_email?: boolean;
|
|
53
|
-
provider: OAuthProvider;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Credentials generated from OAuth flow
|
|
57
|
-
*/
|
|
58
|
-
export interface OAuthCredentials {
|
|
59
|
-
username: string;
|
|
60
|
-
password: string;
|
|
61
|
-
salt?: string;
|
|
62
|
-
key?: any;
|
|
63
|
-
provider: OAuthProvider;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Connection result for OAuth
|
|
67
|
-
*/
|
|
68
|
-
export interface OAuthConnectionResult extends BaseResult {
|
|
69
|
-
provider?: OAuthProvider;
|
|
70
|
-
userInfo?: OAuthUserInfo;
|
|
71
|
-
authUrl?: string;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* OAuth plugin interface
|
|
75
|
-
*/
|
|
76
|
-
export interface OAuthPluginInterface {
|
|
77
|
-
/**
|
|
78
|
-
* Check if OAuth is supported
|
|
79
|
-
*/
|
|
80
|
-
isSupported(): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Get available OAuth providers
|
|
83
|
-
*/
|
|
84
|
-
getAvailableProviders(): OAuthProvider[];
|
|
85
|
-
/**
|
|
86
|
-
* Initiate OAuth flow with a provider
|
|
87
|
-
*/
|
|
88
|
-
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
89
|
-
/**
|
|
90
|
-
* Complete OAuth flow
|
|
91
|
-
*/
|
|
92
|
-
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
93
|
-
/**
|
|
94
|
-
* Generate credentials from OAuth user info
|
|
95
|
-
*/
|
|
96
|
-
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider, masterkey?: string): Promise<OAuthCredentials>;
|
|
97
|
-
/**
|
|
98
|
-
* Login with OAuth
|
|
99
|
-
*/
|
|
100
|
-
login(provider: OAuthProvider): Promise<AuthResult>;
|
|
101
|
-
/**
|
|
102
|
-
* Sign up with OAuth provider
|
|
103
|
-
* @param provider OAuth provider to use
|
|
104
|
-
* @returns Promise with authentication result
|
|
105
|
-
*/
|
|
106
|
-
signUp(provider: OAuthProvider): Promise<SignUpResult>;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Cache entry for OAuth data
|
|
110
|
-
*/
|
|
111
|
-
export interface OAuthCache extends BaseCacheEntry<OAuthUserInfo> {
|
|
112
|
-
provider: OAuthProvider;
|
|
113
|
-
userId: string;
|
|
114
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ISEAPair } from "gun";
|
|
2
|
-
import { BaseConfig, BaseResult, BaseCacheEntry } from "../../interfaces/common";
|
|
3
|
-
import { AuthResult, SignUpResult } from "../../interfaces/shogun";
|
|
4
|
-
/**
|
|
5
|
-
* Result of connection attempt
|
|
6
|
-
*/
|
|
7
|
-
export interface ConnectionResult extends BaseResult {
|
|
8
|
-
address?: string;
|
|
9
|
-
username?: string;
|
|
10
|
-
randomPassword?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Structure for credentials generated via MetaMask
|
|
14
|
-
*/
|
|
15
|
-
export interface Web3ConnectorCredentials {
|
|
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 MetaMask */
|
|
23
|
-
signature: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Ethereum provider interface
|
|
27
|
-
*/
|
|
28
|
-
export interface EthereumProvider {
|
|
29
|
-
request: (args: any) => Promise<any>;
|
|
30
|
-
isMetaMask?: boolean;
|
|
31
|
-
on?: (event: string, handler: (params: any) => void) => void;
|
|
32
|
-
removeListener?: (event: string, handler: (params: any) => void) => void;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Cache entry for signatures
|
|
36
|
-
*/
|
|
37
|
-
export interface SignatureCache extends BaseCacheEntry<string> {
|
|
38
|
-
signature: string;
|
|
39
|
-
address: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* MetaMask configuration options
|
|
43
|
-
*/
|
|
44
|
-
export interface Web3Config extends BaseConfig {
|
|
45
|
-
cacheDuration?: number;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Interfaccia per il plugin MetaMask
|
|
49
|
-
*/
|
|
50
|
-
export interface Web3ConnectorPluginInterface {
|
|
51
|
-
/**
|
|
52
|
-
* Verifica se MetaMask è disponibile nel browser
|
|
53
|
-
* @returns true se MetaMask è disponibile, false altrimenti
|
|
54
|
-
*/
|
|
55
|
-
isAvailable(): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Connette a MetaMask
|
|
58
|
-
* @returns Promise con il risultato della connessione
|
|
59
|
-
*/
|
|
60
|
-
connectMetaMask(): Promise<ConnectionResult>;
|
|
61
|
-
/**
|
|
62
|
-
* Genera credenziali utilizzando MetaMask
|
|
63
|
-
* @param address Indirizzo Ethereum
|
|
64
|
-
* @returns Promise con le credenziali generate
|
|
65
|
-
*/
|
|
66
|
-
generateCredentials(address: string): Promise<ISEAPair>;
|
|
67
|
-
/**
|
|
68
|
-
* Rilascia le risorse e pulisce gli event listener
|
|
69
|
-
*/
|
|
70
|
-
cleanup(): void;
|
|
71
|
-
/**
|
|
72
|
-
* Imposta un provider personalizzato
|
|
73
|
-
* @param rpcUrl URL del provider RPC
|
|
74
|
-
* @param privateKey Chiave privata
|
|
75
|
-
*/
|
|
76
|
-
setCustomProvider(rpcUrl: string, privateKey: string): void;
|
|
77
|
-
/**
|
|
78
|
-
* Ottiene il signer Ethereum
|
|
79
|
-
* @returns Promise con il signer
|
|
80
|
-
*/
|
|
81
|
-
getSigner(): Promise<any>;
|
|
82
|
-
/**
|
|
83
|
-
* Genera una password basata su una firma
|
|
84
|
-
* @param signature Firma
|
|
85
|
-
* @returns Promise con la password generata
|
|
86
|
-
*/
|
|
87
|
-
generatePassword(signature: string): Promise<string>;
|
|
88
|
-
/**
|
|
89
|
-
* Verifica una firma
|
|
90
|
-
* @param message Messaggio firmato
|
|
91
|
-
* @param signature Firma da verificare
|
|
92
|
-
* @returns Promise con l'indirizzo che ha generato la firma
|
|
93
|
-
*/
|
|
94
|
-
verifySignature(message: string, signature: string): Promise<string>;
|
|
95
|
-
/**
|
|
96
|
-
* Login con MetaMask
|
|
97
|
-
* @param address Indirizzo Ethereum
|
|
98
|
-
* @returns Promise con il risultato dell'operazione
|
|
99
|
-
*/
|
|
100
|
-
login(address: string): Promise<AuthResult>;
|
|
101
|
-
/**
|
|
102
|
-
* Sign up with Web3 wallet
|
|
103
|
-
* @param address Ethereum address
|
|
104
|
-
* @returns Promise with authentication result
|
|
105
|
-
*/
|
|
106
|
-
signUp(address: string): Promise<SignUpResult>;
|
|
107
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The MetaMaskAuth class provides functionality for connecting, signing up, and logging in using MetaMask.
|
|
3
|
-
*/
|
|
4
|
-
import { ethers } from "ethers";
|
|
5
|
-
import { EventEmitter } from "../../utils/eventEmitter";
|
|
6
|
-
import { ConnectionResult, EthereumProvider, Web3Config } from "./types";
|
|
7
|
-
import { ISEAPair } from "gun";
|
|
8
|
-
declare global {
|
|
9
|
-
interface Window {
|
|
10
|
-
ethereum?: EthereumProvider;
|
|
11
|
-
Web3Connector?: typeof Web3Connector;
|
|
12
|
-
_ethereumProviders?: EthereumProvider[];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
declare global {
|
|
16
|
-
namespace NodeJS {
|
|
17
|
-
interface Global {
|
|
18
|
-
web3Connector?: typeof Web3Connector;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Class for MetaMask connection
|
|
24
|
-
*/
|
|
25
|
-
declare class Web3Connector extends EventEmitter {
|
|
26
|
-
private readonly MESSAGE_TO_SIGN;
|
|
27
|
-
private readonly DEFAULT_CONFIG;
|
|
28
|
-
private readonly config;
|
|
29
|
-
private readonly signatureCache;
|
|
30
|
-
private provider;
|
|
31
|
-
private customProvider;
|
|
32
|
-
private customWallet;
|
|
33
|
-
constructor(config?: Partial<Web3Config>);
|
|
34
|
-
/**
|
|
35
|
-
* Initialize the provider synchronously with fallback mechanisms
|
|
36
|
-
* to handle conflicts between multiple wallet providers
|
|
37
|
-
*/
|
|
38
|
-
private initProvider;
|
|
39
|
-
/**
|
|
40
|
-
* Get available Ethereum provider from multiple possible sources
|
|
41
|
-
*/
|
|
42
|
-
private getAvailableEthereumProvider;
|
|
43
|
-
/**
|
|
44
|
-
* Initialize the BrowserProvider (async method for explicit calls)
|
|
45
|
-
*/
|
|
46
|
-
setupProvider(): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Setup MetaMask event listeners using BrowserProvider
|
|
49
|
-
*/
|
|
50
|
-
private setupEventListeners;
|
|
51
|
-
/**
|
|
52
|
-
* Cleanup event listeners
|
|
53
|
-
*/
|
|
54
|
-
cleanup(): void;
|
|
55
|
-
/**
|
|
56
|
-
* Get cached signature if valid
|
|
57
|
-
*/
|
|
58
|
-
private getCachedSignature;
|
|
59
|
-
/**
|
|
60
|
-
* Cache signature
|
|
61
|
-
*/
|
|
62
|
-
private cacheSignature;
|
|
63
|
-
/**
|
|
64
|
-
* Validates that the address is valid
|
|
65
|
-
*/
|
|
66
|
-
private validateAddress;
|
|
67
|
-
/**
|
|
68
|
-
* Connects to MetaMask with retry logic using BrowserProvider
|
|
69
|
-
*/
|
|
70
|
-
connectMetaMask(): Promise<ConnectionResult>;
|
|
71
|
-
/**
|
|
72
|
-
* Generates credentials for the given address
|
|
73
|
-
*/
|
|
74
|
-
generateCredentials(address: string): Promise<ISEAPair>;
|
|
75
|
-
/**
|
|
76
|
-
* Generates credentials from a signature
|
|
77
|
-
*/
|
|
78
|
-
private generateCredentialsFromSignature;
|
|
79
|
-
/**
|
|
80
|
-
* Generates fallback credentials (for testing/development)
|
|
81
|
-
*/
|
|
82
|
-
private generateFallbackCredentials;
|
|
83
|
-
/**
|
|
84
|
-
* Checks if MetaMask is available
|
|
85
|
-
*/
|
|
86
|
-
static isMetaMaskAvailable(): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Requests signature with timeout
|
|
89
|
-
*/
|
|
90
|
-
private requestSignatureWithTimeout;
|
|
91
|
-
/**
|
|
92
|
-
* Checks if the connector is available
|
|
93
|
-
*/
|
|
94
|
-
isAvailable(): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Sets a custom provider for testing/development
|
|
97
|
-
*/
|
|
98
|
-
setCustomProvider(rpcUrl: string, privateKey: string): void;
|
|
99
|
-
/**
|
|
100
|
-
* Get active signer instance using BrowserProvider
|
|
101
|
-
*/
|
|
102
|
-
getSigner(): Promise<ethers.Signer>;
|
|
103
|
-
/**
|
|
104
|
-
* Get active provider instance using BrowserProvider
|
|
105
|
-
*/
|
|
106
|
-
getProvider(): Promise<ethers.JsonRpcProvider | ethers.BrowserProvider>;
|
|
107
|
-
/**
|
|
108
|
-
* Generate deterministic password from signature
|
|
109
|
-
* @param signature - Cryptographic signature
|
|
110
|
-
* @returns 64-character hex string
|
|
111
|
-
* @throws {Error} For invalid signature
|
|
112
|
-
*/
|
|
113
|
-
generatePassword(signature: string): Promise<string>;
|
|
114
|
-
/**
|
|
115
|
-
* Verify message signature
|
|
116
|
-
* @param message - Original signed message
|
|
117
|
-
* @param signature - Cryptographic signature
|
|
118
|
-
* @returns Recovered Ethereum address
|
|
119
|
-
* @throws {Error} For invalid inputs
|
|
120
|
-
*/
|
|
121
|
-
verifySignature(message: string, signature: string): Promise<string>;
|
|
122
|
-
/**
|
|
123
|
-
* Get browser-based Ethereum signer
|
|
124
|
-
* @returns Browser provider signer
|
|
125
|
-
* @throws {Error} If MetaMask not detected
|
|
126
|
-
*/
|
|
127
|
-
getEthereumSigner(): Promise<ethers.Signer>;
|
|
128
|
-
}
|
|
129
|
-
export { Web3Connector };
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { BasePlugin } from "../base";
|
|
2
|
-
import { ShogunCore } from "../../core";
|
|
3
|
-
import { Web3SigningCredential } from "./web3Signer";
|
|
4
|
-
import { ConnectionResult, Web3ConnectorPluginInterface } from "./types";
|
|
5
|
-
import { ethers } from "ethers";
|
|
6
|
-
import { AuthResult, SignUpResult } from "../../interfaces/shogun";
|
|
7
|
-
import { ISEAPair } from "gun";
|
|
8
|
-
/**
|
|
9
|
-
* Plugin per la gestione delle funzionalità Web3 in ShogunCore
|
|
10
|
-
*/
|
|
11
|
-
export declare class Web3ConnectorPlugin extends BasePlugin implements Web3ConnectorPluginInterface {
|
|
12
|
-
name: string;
|
|
13
|
-
version: string;
|
|
14
|
-
description: string;
|
|
15
|
-
private Web3;
|
|
16
|
-
private signer;
|
|
17
|
-
/**
|
|
18
|
-
* @inheritdoc
|
|
19
|
-
*/
|
|
20
|
-
initialize(core: ShogunCore): void;
|
|
21
|
-
/**
|
|
22
|
-
* @inheritdoc
|
|
23
|
-
*/
|
|
24
|
-
destroy(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Assicura che il modulo Web3 sia inizializzato
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
private assertMetaMask;
|
|
30
|
-
/**
|
|
31
|
-
* Assicura che il signer sia inizializzato
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
private assertSigner;
|
|
35
|
-
/**
|
|
36
|
-
* @inheritdoc
|
|
37
|
-
*/
|
|
38
|
-
isAvailable(): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* @inheritdoc
|
|
41
|
-
*/
|
|
42
|
-
connectMetaMask(): Promise<ConnectionResult>;
|
|
43
|
-
/**
|
|
44
|
-
* @inheritdoc
|
|
45
|
-
*/
|
|
46
|
-
generateCredentials(address: string): Promise<ISEAPair>;
|
|
47
|
-
/**
|
|
48
|
-
* @inheritdoc
|
|
49
|
-
*/
|
|
50
|
-
cleanup(): void;
|
|
51
|
-
/**
|
|
52
|
-
* @inheritdoc
|
|
53
|
-
*/
|
|
54
|
-
setCustomProvider(rpcUrl: string, privateKey: string): void;
|
|
55
|
-
/**
|
|
56
|
-
* @inheritdoc
|
|
57
|
-
*/
|
|
58
|
-
getSigner(): Promise<ethers.Signer>;
|
|
59
|
-
/**
|
|
60
|
-
* @inheritdoc
|
|
61
|
-
*/
|
|
62
|
-
getProvider(): Promise<ethers.JsonRpcProvider | ethers.BrowserProvider>;
|
|
63
|
-
/**
|
|
64
|
-
* @inheritdoc
|
|
65
|
-
*/
|
|
66
|
-
generatePassword(signature: string): Promise<string>;
|
|
67
|
-
/**
|
|
68
|
-
* @inheritdoc
|
|
69
|
-
*/
|
|
70
|
-
verifySignature(message: string, signature: string): Promise<string>;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new Web3 signing credential
|
|
73
|
-
* CONSISTENT with normal Web3 approach
|
|
74
|
-
*/
|
|
75
|
-
createSigningCredential(address: string): Promise<Web3SigningCredential>;
|
|
76
|
-
/**
|
|
77
|
-
* Creates an authenticator function for Web3 signing
|
|
78
|
-
*/
|
|
79
|
-
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
80
|
-
/**
|
|
81
|
-
* Creates a derived key pair from Web3 credential
|
|
82
|
-
*/
|
|
83
|
-
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
84
|
-
pub: string;
|
|
85
|
-
priv: string;
|
|
86
|
-
epub: string;
|
|
87
|
-
epriv: string;
|
|
88
|
-
}>;
|
|
89
|
-
/**
|
|
90
|
-
* Signs data with derived keys after Web3 verification
|
|
91
|
-
*/
|
|
92
|
-
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
93
|
-
/**
|
|
94
|
-
* Get signing credential by address
|
|
95
|
-
*/
|
|
96
|
-
getSigningCredential(address: string): Web3SigningCredential | undefined;
|
|
97
|
-
/**
|
|
98
|
-
* List all signing credentials
|
|
99
|
-
*/
|
|
100
|
-
listSigningCredentials(): Web3SigningCredential[];
|
|
101
|
-
/**
|
|
102
|
-
* Remove a signing credential
|
|
103
|
-
*/
|
|
104
|
-
removeSigningCredential(address: string): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Creates a Gun user from Web3 signing credential
|
|
107
|
-
* This ensures the SAME user is created as with normal approach
|
|
108
|
-
*/
|
|
109
|
-
createGunUserFromSigningCredential(address: string): Promise<{
|
|
110
|
-
success: boolean;
|
|
111
|
-
userPub?: string;
|
|
112
|
-
error?: string;
|
|
113
|
-
}>;
|
|
114
|
-
/**
|
|
115
|
-
* Get the Gun user public key for a signing credential
|
|
116
|
-
*/
|
|
117
|
-
getGunUserPubFromSigningCredential(address: string): Promise<string | undefined>;
|
|
118
|
-
/**
|
|
119
|
-
* Get the password (for consistency checking)
|
|
120
|
-
*/
|
|
121
|
-
getPassword(address: string): string | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* Verify consistency between oneshot and normal approaches
|
|
124
|
-
* This ensures both approaches create the same Gun user
|
|
125
|
-
*/
|
|
126
|
-
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
127
|
-
consistent: boolean;
|
|
128
|
-
actualUserPub?: string;
|
|
129
|
-
expectedUserPub?: string;
|
|
130
|
-
}>;
|
|
131
|
-
/**
|
|
132
|
-
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
133
|
-
* This is the recommended method for oneshot signing with full consistency
|
|
134
|
-
*/
|
|
135
|
-
setupConsistentOneshotSigning(address: string): Promise<{
|
|
136
|
-
credential: Web3SigningCredential;
|
|
137
|
-
authenticator: (data: any) => Promise<string>;
|
|
138
|
-
gunUser: {
|
|
139
|
-
success: boolean;
|
|
140
|
-
userPub?: string;
|
|
141
|
-
error?: string;
|
|
142
|
-
};
|
|
143
|
-
username: string;
|
|
144
|
-
password: string;
|
|
145
|
-
}>;
|
|
146
|
-
/**
|
|
147
|
-
* Login con Web3
|
|
148
|
-
* @param address - Indirizzo Ethereum
|
|
149
|
-
* @returns {Promise<AuthResult>} Risultato dell'autenticazione
|
|
150
|
-
* @description Autentica l'utente usando le credenziali del wallet Web3 dopo la verifica della firma
|
|
151
|
-
*/
|
|
152
|
-
login(address: string): Promise<AuthResult>;
|
|
153
|
-
/**
|
|
154
|
-
* Register new user with Web3 wallet
|
|
155
|
-
* @param address - Ethereum address
|
|
156
|
-
* @returns {Promise<SignUpResult>} Registration result
|
|
157
|
-
*/
|
|
158
|
-
signUp(address: string): Promise<SignUpResult>;
|
|
159
|
-
}
|
|
160
|
-
export type { Web3ConnectorPluginInterface } from "./types";
|