shogun-core 1.2.7 → 1.2.8
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 +0 -1
- package/dist/browser/shogun-core.js +1 -1
- package/dist/browser/shogun-core.js.LICENSE.txt +2 -0
- package/dist/browser/shogun-core.light.js +1 -1
- package/dist/browser/shogun-core.vendors.light.js +1 -1
- package/dist/core.js +31 -71
- package/dist/gundb/{instance.js → gunInstance.js} +135 -115
- package/dist/gundb/index.js +3 -20
- package/dist/plugins/index.js +23 -1
- package/dist/plugins/nostr/index.js +1 -0
- package/dist/plugins/nostr/nostrChain.js +128 -0
- package/dist/plugins/nostr/nostrConnector.js +42 -7
- package/dist/plugins/nostr/nostrConnectorPlugin.js +157 -1
- package/dist/plugins/nostr/nostrSigner.js +343 -0
- package/dist/plugins/oauth/index.js +13 -0
- package/dist/plugins/oauth/oauthChain.js +161 -0
- package/dist/plugins/oauth/oauthConnector.js +542 -0
- package/dist/plugins/oauth/oauthPlugin.js +302 -0
- package/dist/plugins/oauth/types.js +2 -0
- package/dist/plugins/web3/index.js +1 -0
- package/dist/plugins/web3/web3Chain.js +77 -2
- package/dist/plugins/web3/web3Connector.js +159 -37
- package/dist/plugins/web3/web3ConnectorPlugin.js +157 -1
- package/dist/plugins/web3/web3Signer.js +268 -0
- package/dist/plugins/webauthn/webauthnChain.js +78 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +154 -1
- package/dist/plugins/webauthn/webauthnSigner.js +318 -0
- package/dist/storage/storage.js +0 -8
- package/dist/types/core.d.ts +10 -34
- package/dist/types/gundb/gun-es/gun-es.d.ts +1 -0
- package/dist/types/gundb/{instance.d.ts → gunInstance.d.ts} +2 -2
- package/dist/types/gundb/index.d.ts +1 -4
- package/dist/types/plugins/index.d.ts +4 -0
- package/dist/types/plugins/nostr/index.d.ts +1 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +3 -2
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +82 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +104 -0
- package/dist/types/plugins/oauth/index.d.ts +4 -0
- package/dist/types/plugins/oauth/oauthChain.d.ts +2 -0
- package/dist/types/plugins/oauth/oauthConnector.d.ts +100 -0
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +89 -0
- package/dist/types/plugins/oauth/types.d.ts +106 -0
- package/dist/types/plugins/web3/index.d.ts +1 -0
- package/dist/types/plugins/web3/types.d.ts +1 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +8 -2
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +82 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +93 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +81 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +90 -0
- package/dist/types/shogun.js +1 -28
- package/dist/types/types/events.d.ts +2 -2
- package/dist/types/types/shogun.d.ts +13 -49
- package/package.json +2 -1
- package/dist/browser.js +0 -107
- package/dist/contracts/base.js +0 -152
- package/dist/contracts/entryPoint.js +0 -407
- package/dist/contracts/index.js +0 -47
- package/dist/contracts/registry.js +0 -259
- package/dist/contracts/relay.js +0 -494
- package/dist/contracts/utils.js +0 -582
- package/dist/types/browser.d.ts +0 -27
- package/dist/types/contracts/base.d.ts +0 -82
- package/dist/types/contracts/entryPoint.d.ts +0 -138
- package/dist/types/contracts/index.d.ts +0 -17
- package/dist/types/contracts/registry.d.ts +0 -97
- package/dist/types/contracts/relay.d.ts +0 -165
- package/dist/types/contracts/utils.d.ts +0 -173
|
@@ -12,3 +12,7 @@ export { NostrConnector } from "./nostr/nostrConnector";
|
|
|
12
12
|
export { NostrConnectorPlugin } from "./nostr/nostrConnectorPlugin";
|
|
13
13
|
export type { NostrConnectorPluginInterface, NostrConnectorCredentials, NostrConnectorKeyPair, NostrConnectorConfig, AlbyProvider, NostrProvider, } from "./nostr/types";
|
|
14
14
|
export { default as nostrChain } from "./nostr/nostrChain";
|
|
15
|
+
export { OAuthConnector } from "./oauth/oauthConnector";
|
|
16
|
+
export { OAuthPlugin } from "./oauth/oauthPlugin";
|
|
17
|
+
export * from "./oauth/types";
|
|
18
|
+
export { default as oauthChain } from "./oauth/oauthChain";
|
|
@@ -10,7 +10,7 @@ declare global {
|
|
|
10
10
|
/**
|
|
11
11
|
* Class for Bitcoin wallet connections and operations
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
declare class NostrConnector extends EventEmitter {
|
|
14
14
|
private readonly MESSAGE_TO_SIGN;
|
|
15
15
|
private readonly DEFAULT_CONFIG;
|
|
16
16
|
private readonly config;
|
|
@@ -86,7 +86,7 @@ export declare class NostrConnector extends EventEmitter {
|
|
|
86
86
|
/**
|
|
87
87
|
* Verify a signature
|
|
88
88
|
*/
|
|
89
|
-
verifySignature(message: string, signature: string, address:
|
|
89
|
+
verifySignature(message: string, signature: string, address: any): Promise<boolean>;
|
|
90
90
|
/**
|
|
91
91
|
* Get the currently connected address
|
|
92
92
|
*/
|
|
@@ -104,3 +104,4 @@ export declare class NostrConnector extends EventEmitter {
|
|
|
104
104
|
*/
|
|
105
105
|
private requestSignature;
|
|
106
106
|
}
|
|
107
|
+
export { NostrConnector };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BasePlugin } from "../base";
|
|
2
2
|
import { ShogunCore } from "../../index";
|
|
3
|
+
import { NostrSigningCredential } from "./nostrSigner";
|
|
3
4
|
import { NostrConnectorCredentials, ConnectionResult, NostrConnectorPluginInterface } from "./types";
|
|
4
5
|
import { AuthResult } from "../../types/shogun";
|
|
5
6
|
/**
|
|
@@ -11,6 +12,7 @@ export declare class NostrConnectorPlugin extends BasePlugin implements NostrCon
|
|
|
11
12
|
version: string;
|
|
12
13
|
description: string;
|
|
13
14
|
private bitcoinConnector;
|
|
15
|
+
private signer;
|
|
14
16
|
/**
|
|
15
17
|
* @inheritdoc
|
|
16
18
|
*/
|
|
@@ -24,6 +26,11 @@ export declare class NostrConnectorPlugin extends BasePlugin implements NostrCon
|
|
|
24
26
|
* @private
|
|
25
27
|
*/
|
|
26
28
|
private assertBitcoinConnector;
|
|
29
|
+
/**
|
|
30
|
+
* Assicura che il signer sia inizializzato
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private assertSigner;
|
|
27
34
|
/**
|
|
28
35
|
* @inheritdoc
|
|
29
36
|
*/
|
|
@@ -62,6 +69,81 @@ export declare class NostrConnectorPlugin extends BasePlugin implements NostrCon
|
|
|
62
69
|
* @inheritdoc
|
|
63
70
|
*/
|
|
64
71
|
generatePassword(signature: string): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new Nostr signing credential
|
|
74
|
+
* CONSISTENT with normal Nostr approach
|
|
75
|
+
*/
|
|
76
|
+
createSigningCredential(address: string): Promise<NostrSigningCredential>;
|
|
77
|
+
/**
|
|
78
|
+
* Creates an authenticator function for Nostr signing
|
|
79
|
+
*/
|
|
80
|
+
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a derived key pair from Nostr credential
|
|
83
|
+
*/
|
|
84
|
+
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
85
|
+
pub: string;
|
|
86
|
+
priv: string;
|
|
87
|
+
epub: string;
|
|
88
|
+
epriv: string;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Signs data with derived keys after Nostr verification
|
|
92
|
+
*/
|
|
93
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Get signing credential by address
|
|
96
|
+
*/
|
|
97
|
+
getSigningCredential(address: string): NostrSigningCredential | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* List all signing credentials
|
|
100
|
+
*/
|
|
101
|
+
listSigningCredentials(): NostrSigningCredential[];
|
|
102
|
+
/**
|
|
103
|
+
* Remove a signing credential
|
|
104
|
+
*/
|
|
105
|
+
removeSigningCredential(address: string): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a Gun user from Nostr signing credential
|
|
108
|
+
* This ensures the SAME user is created as with normal approach
|
|
109
|
+
*/
|
|
110
|
+
createGunUserFromSigningCredential(address: string): Promise<{
|
|
111
|
+
success: boolean;
|
|
112
|
+
userPub?: string;
|
|
113
|
+
error?: string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Get the Gun user public key for a signing credential
|
|
117
|
+
*/
|
|
118
|
+
getGunUserPubFromSigningCredential(address: string): string | undefined;
|
|
119
|
+
/**
|
|
120
|
+
* Get the password (for consistency checking)
|
|
121
|
+
*/
|
|
122
|
+
getPassword(address: string): string | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Verify consistency between oneshot and normal approaches
|
|
125
|
+
* This ensures both approaches create the same Gun user
|
|
126
|
+
*/
|
|
127
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
128
|
+
consistent: boolean;
|
|
129
|
+
actualUserPub?: string;
|
|
130
|
+
expectedUserPub?: string;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
134
|
+
* This is the recommended method for oneshot signing with full consistency
|
|
135
|
+
*/
|
|
136
|
+
setupConsistentOneshotSigning(address: string): Promise<{
|
|
137
|
+
credential: NostrSigningCredential;
|
|
138
|
+
authenticator: (data: any) => Promise<string>;
|
|
139
|
+
gunUser: {
|
|
140
|
+
success: boolean;
|
|
141
|
+
userPub?: string;
|
|
142
|
+
error?: string;
|
|
143
|
+
};
|
|
144
|
+
username: string;
|
|
145
|
+
password: string;
|
|
146
|
+
}>;
|
|
65
147
|
/**
|
|
66
148
|
* Login with Bitcoin wallet
|
|
67
149
|
* @param address - Bitcoin address
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { NostrConnector } from "./nostrConnector";
|
|
2
|
+
/**
|
|
3
|
+
* Nostr Signing Credential for oneshot signing
|
|
4
|
+
*/
|
|
5
|
+
export interface NostrSigningCredential {
|
|
6
|
+
address: string;
|
|
7
|
+
signature: string;
|
|
8
|
+
message: string;
|
|
9
|
+
username: string;
|
|
10
|
+
password: string;
|
|
11
|
+
gunUserPub?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Nostr Signer - Provides oneshot signing functionality
|
|
15
|
+
* Similar to webauthn.js but for Nostr/Bitcoin wallets
|
|
16
|
+
* CONSISTENT with normal Nostr approach
|
|
17
|
+
*/
|
|
18
|
+
export declare class NostrSigner {
|
|
19
|
+
private nostrConnector;
|
|
20
|
+
private credentials;
|
|
21
|
+
private readonly MESSAGE_TO_SIGN;
|
|
22
|
+
constructor(nostrConnector?: NostrConnector);
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new Nostr signing credential
|
|
25
|
+
* CONSISTENT with normal Nostr approach
|
|
26
|
+
*/
|
|
27
|
+
createSigningCredential(address: string): Promise<NostrSigningCredential>;
|
|
28
|
+
/**
|
|
29
|
+
* Validates address using the same logic as NostrConnector
|
|
30
|
+
*/
|
|
31
|
+
private validateAddress;
|
|
32
|
+
/**
|
|
33
|
+
* Generate deterministic signature using the SAME approach as NostrConnector
|
|
34
|
+
*/
|
|
35
|
+
private generateDeterministicSignature;
|
|
36
|
+
/**
|
|
37
|
+
* Generate password using the SAME approach as NostrConnector
|
|
38
|
+
*/
|
|
39
|
+
private generatePassword;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an authenticator function compatible with SEA.sign
|
|
42
|
+
* This is the key function that makes it work like webauthn.js but for Nostr
|
|
43
|
+
*/
|
|
44
|
+
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Sign data using the credential
|
|
47
|
+
*/
|
|
48
|
+
private signData;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a derived key pair from Nostr credential
|
|
51
|
+
* CONSISTENT with normal approach: uses password as seed
|
|
52
|
+
*/
|
|
53
|
+
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
54
|
+
pub: string;
|
|
55
|
+
priv: string;
|
|
56
|
+
epub: string;
|
|
57
|
+
epriv: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a Gun user from Nostr credential
|
|
61
|
+
* This ensures the SAME user is created as with normal approach
|
|
62
|
+
*/
|
|
63
|
+
createGunUser(address: string, gunInstance: any): Promise<{
|
|
64
|
+
success: boolean;
|
|
65
|
+
userPub?: string;
|
|
66
|
+
error?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Signs data using Nostr + derived keys
|
|
70
|
+
* This provides a hybrid approach: Nostr for user verification + derived keys for actual signing
|
|
71
|
+
* CONSISTENT with normal approach
|
|
72
|
+
*/
|
|
73
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the Gun user public key for a credential
|
|
76
|
+
* This allows checking if the same user would be created
|
|
77
|
+
*/
|
|
78
|
+
getGunUserPub(address: string): string | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Get the password (for consistency checking)
|
|
81
|
+
*/
|
|
82
|
+
getPassword(address: string): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Check if this credential would create the same Gun user as normal approach
|
|
85
|
+
*/
|
|
86
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
87
|
+
consistent: boolean;
|
|
88
|
+
actualUserPub?: string;
|
|
89
|
+
expectedUserPub?: string;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* Get credential by address
|
|
93
|
+
*/
|
|
94
|
+
getCredential(address: string): NostrSigningCredential | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* List all stored credentials
|
|
97
|
+
*/
|
|
98
|
+
listCredentials(): NostrSigningCredential[];
|
|
99
|
+
/**
|
|
100
|
+
* Remove a credential
|
|
101
|
+
*/
|
|
102
|
+
removeCredential(address: string): boolean;
|
|
103
|
+
}
|
|
104
|
+
export default NostrSigner;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { OAuthConnector } from "./oauthConnector";
|
|
2
|
+
export { OAuthPlugin } from "./oauthPlugin";
|
|
3
|
+
export type { OAuthPluginInterface, OAuthConfig, OAuthProvider, OAuthCredentials, OAuthConnectionResult, OAuthUserInfo, } from "./types";
|
|
4
|
+
export { default as oauthChain } from "./oauthChain";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { EventEmitter } from "../../utils/eventEmitter";
|
|
2
|
+
import { OAuthConfig, OAuthProvider, OAuthUserInfo, OAuthCredentials, OAuthConnectionResult } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* OAuth Connector
|
|
5
|
+
*/
|
|
6
|
+
export declare class OAuthConnector extends EventEmitter {
|
|
7
|
+
private readonly DEFAULT_CONFIG;
|
|
8
|
+
private config;
|
|
9
|
+
private readonly userCache;
|
|
10
|
+
private readonly memoryStorage;
|
|
11
|
+
constructor(config?: Partial<OAuthConfig>);
|
|
12
|
+
/**
|
|
13
|
+
* Update the connector configuration
|
|
14
|
+
* @param config - New configuration options
|
|
15
|
+
*/
|
|
16
|
+
updateConfig(config: Partial<OAuthConfig>): void;
|
|
17
|
+
/**
|
|
18
|
+
* Get origin URL (browser or Node.js compatible)
|
|
19
|
+
*/
|
|
20
|
+
private getOrigin;
|
|
21
|
+
/**
|
|
22
|
+
* Storage abstraction (browser sessionStorage or Node.js Map)
|
|
23
|
+
*/
|
|
24
|
+
private setItem;
|
|
25
|
+
private getItem;
|
|
26
|
+
private removeItem;
|
|
27
|
+
/**
|
|
28
|
+
* Check if OAuth is supported
|
|
29
|
+
*/
|
|
30
|
+
isSupported(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Get available OAuth providers
|
|
33
|
+
*/
|
|
34
|
+
getAvailableProviders(): OAuthProvider[];
|
|
35
|
+
/**
|
|
36
|
+
* Generate PKCE challenge for secure OAuth flow
|
|
37
|
+
*/
|
|
38
|
+
private generatePKCEChallenge;
|
|
39
|
+
/**
|
|
40
|
+
* Calculate the PKCE code challenge from a code verifier.
|
|
41
|
+
* Hashes the verifier using SHA-256 and then base64url encodes it.
|
|
42
|
+
* @param verifier The code verifier string.
|
|
43
|
+
* @returns The base64url-encoded SHA-256 hash of the verifier.
|
|
44
|
+
*/
|
|
45
|
+
private calculatePKCECodeChallenge;
|
|
46
|
+
/**
|
|
47
|
+
* Encodes a buffer into a Base64URL-encoded string.
|
|
48
|
+
* @param buffer The buffer to encode.
|
|
49
|
+
* @returns The Base64URL-encoded string.
|
|
50
|
+
*/
|
|
51
|
+
private base64urlEncode;
|
|
52
|
+
/**
|
|
53
|
+
* Generate cryptographically secure random string
|
|
54
|
+
*/
|
|
55
|
+
private generateRandomString;
|
|
56
|
+
/**
|
|
57
|
+
* Initiate OAuth flow with a provider
|
|
58
|
+
*/
|
|
59
|
+
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Complete OAuth flow
|
|
62
|
+
*/
|
|
63
|
+
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Generate credentials from OAuth user info
|
|
66
|
+
*/
|
|
67
|
+
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
|
|
68
|
+
/**
|
|
69
|
+
* Generate deterministic password
|
|
70
|
+
*/
|
|
71
|
+
private generateDeterministicPassword;
|
|
72
|
+
/**
|
|
73
|
+
* Exchange authorization code for access token
|
|
74
|
+
*/
|
|
75
|
+
private exchangeCodeForToken;
|
|
76
|
+
/**
|
|
77
|
+
* Get user info from OAuth provider
|
|
78
|
+
*/
|
|
79
|
+
private fetchUserInfo;
|
|
80
|
+
/**
|
|
81
|
+
* Normalize user info across different providers
|
|
82
|
+
*/
|
|
83
|
+
private normalizeUserInfo;
|
|
84
|
+
/**
|
|
85
|
+
* Cache user info
|
|
86
|
+
*/
|
|
87
|
+
private cacheUserInfo;
|
|
88
|
+
/**
|
|
89
|
+
* Get cached user info
|
|
90
|
+
*/
|
|
91
|
+
getCachedUserInfo(userId: string, provider: OAuthProvider): OAuthUserInfo | null;
|
|
92
|
+
/**
|
|
93
|
+
* Clear user info cache
|
|
94
|
+
*/
|
|
95
|
+
clearUserCache(userId?: string, provider?: OAuthProvider): void;
|
|
96
|
+
/**
|
|
97
|
+
* Cleanup resources
|
|
98
|
+
*/
|
|
99
|
+
cleanup(): void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BasePlugin } from "../base";
|
|
2
|
+
import { ShogunCore } from "../../index";
|
|
3
|
+
import { OAuthPluginInterface, OAuthConfig, OAuthProvider, OAuthConnectionResult, OAuthCredentials, OAuthUserInfo } from "./types";
|
|
4
|
+
import { AuthResult } from "../../types/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
|
+
/**
|
|
16
|
+
* @inheritdoc
|
|
17
|
+
*/
|
|
18
|
+
initialize(core: ShogunCore): void;
|
|
19
|
+
/**
|
|
20
|
+
* Configure the OAuth plugin with provider settings
|
|
21
|
+
* @param config - Configuration options for OAuth
|
|
22
|
+
*/
|
|
23
|
+
configure(config: Partial<OAuthConfig>): void;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
27
|
+
destroy(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Ensure that the OAuth connector is initialized
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private assertOAuthConnector;
|
|
33
|
+
/**
|
|
34
|
+
* @inheritdoc
|
|
35
|
+
*/
|
|
36
|
+
isSupported(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* @inheritdoc
|
|
39
|
+
*/
|
|
40
|
+
getAvailableProviders(): OAuthProvider[];
|
|
41
|
+
/**
|
|
42
|
+
* @inheritdoc
|
|
43
|
+
*/
|
|
44
|
+
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
45
|
+
/**
|
|
46
|
+
* @inheritdoc
|
|
47
|
+
*/
|
|
48
|
+
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
49
|
+
/**
|
|
50
|
+
* @inheritdoc
|
|
51
|
+
*/
|
|
52
|
+
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
|
|
53
|
+
/**
|
|
54
|
+
* Login with OAuth
|
|
55
|
+
* @param provider - OAuth provider to use
|
|
56
|
+
* @returns {Promise<AuthResult>} Authentication result
|
|
57
|
+
* @description Authenticates user using OAuth with external providers
|
|
58
|
+
*/
|
|
59
|
+
login(provider: OAuthProvider): Promise<AuthResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Sign up with OAuth
|
|
62
|
+
* @param provider - OAuth provider to use
|
|
63
|
+
* @returns {Promise<AuthResult>} Registration result
|
|
64
|
+
* @description Creates a new user account using OAuth with external providers
|
|
65
|
+
*/
|
|
66
|
+
signUp(provider: OAuthProvider): Promise<AuthResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Handle OAuth callback (for frontend integration)
|
|
69
|
+
* This method would be called when the OAuth provider redirects back
|
|
70
|
+
*/
|
|
71
|
+
handleOAuthCallback(provider: OAuthProvider, authCode: string, state?: string): Promise<AuthResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Private helper to login or sign up a user
|
|
74
|
+
*/
|
|
75
|
+
private _loginOrSignUp;
|
|
76
|
+
/**
|
|
77
|
+
* Alias for handleOAuthCallback for backward compatibility
|
|
78
|
+
* @deprecated Use handleOAuthCallback instead
|
|
79
|
+
*/
|
|
80
|
+
handleSimpleOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<AuthResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Get cached user info for a user
|
|
83
|
+
*/
|
|
84
|
+
getCachedUserInfo(userId: string, provider: OAuthProvider): OAuthUserInfo | null;
|
|
85
|
+
/**
|
|
86
|
+
* Clear user info cache
|
|
87
|
+
*/
|
|
88
|
+
clearUserCache(userId?: string, provider?: OAuthProvider): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { BaseConfig, BaseResult, BaseCacheEntry } from "../../types/common";
|
|
2
|
+
import { AuthResult } from "../../types/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
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* OAuth configuration
|
|
21
|
+
*/
|
|
22
|
+
export interface OAuthConfig extends BaseConfig {
|
|
23
|
+
providers: Partial<Record<OAuthProvider, OAuthProviderConfig>>;
|
|
24
|
+
usePKCE?: boolean;
|
|
25
|
+
cacheDuration?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* OAuth token response
|
|
29
|
+
*/
|
|
30
|
+
export interface OAuthTokenResponse {
|
|
31
|
+
access_token: string;
|
|
32
|
+
token_type: string;
|
|
33
|
+
expires_in: number;
|
|
34
|
+
refresh_token?: string;
|
|
35
|
+
scope?: string;
|
|
36
|
+
id_token?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* User info from OAuth provider
|
|
40
|
+
*/
|
|
41
|
+
export interface OAuthUserInfo {
|
|
42
|
+
id: string;
|
|
43
|
+
email?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
picture?: string;
|
|
46
|
+
verified_email?: boolean;
|
|
47
|
+
provider: OAuthProvider;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Credentials generated from OAuth flow
|
|
51
|
+
*/
|
|
52
|
+
export interface OAuthCredentials {
|
|
53
|
+
username: string;
|
|
54
|
+
password: string;
|
|
55
|
+
salt?: string;
|
|
56
|
+
key?: any;
|
|
57
|
+
provider: OAuthProvider;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Connection result for OAuth
|
|
61
|
+
*/
|
|
62
|
+
export interface OAuthConnectionResult extends BaseResult {
|
|
63
|
+
provider?: OAuthProvider;
|
|
64
|
+
userInfo?: OAuthUserInfo;
|
|
65
|
+
authUrl?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* OAuth plugin interface
|
|
69
|
+
*/
|
|
70
|
+
export interface OAuthPluginInterface {
|
|
71
|
+
/**
|
|
72
|
+
* Check if OAuth is supported
|
|
73
|
+
*/
|
|
74
|
+
isSupported(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get available OAuth providers
|
|
77
|
+
*/
|
|
78
|
+
getAvailableProviders(): OAuthProvider[];
|
|
79
|
+
/**
|
|
80
|
+
* Initiate OAuth flow with a provider
|
|
81
|
+
*/
|
|
82
|
+
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Complete OAuth flow
|
|
85
|
+
*/
|
|
86
|
+
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Generate credentials from OAuth user info
|
|
89
|
+
*/
|
|
90
|
+
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials>;
|
|
91
|
+
/**
|
|
92
|
+
* Login with OAuth
|
|
93
|
+
*/
|
|
94
|
+
login(provider: OAuthProvider): Promise<AuthResult>;
|
|
95
|
+
/**
|
|
96
|
+
* Sign up with OAuth
|
|
97
|
+
*/
|
|
98
|
+
signUp(provider: OAuthProvider): Promise<AuthResult>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Cache entry for OAuth data
|
|
102
|
+
*/
|
|
103
|
+
export interface OAuthCache extends BaseCacheEntry<OAuthUserInfo> {
|
|
104
|
+
provider: OAuthProvider;
|
|
105
|
+
userId: string;
|
|
106
|
+
}
|
|
@@ -8,6 +8,7 @@ declare global {
|
|
|
8
8
|
interface Window {
|
|
9
9
|
ethereum?: EthereumProvider;
|
|
10
10
|
Web3Connector?: typeof Web3Connector;
|
|
11
|
+
_ethereumProviders?: EthereumProvider[];
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
declare global {
|
|
@@ -30,9 +31,14 @@ declare class Web3Connector extends EventEmitter {
|
|
|
30
31
|
private customWallet;
|
|
31
32
|
constructor(config?: Partial<Web3Config>);
|
|
32
33
|
/**
|
|
33
|
-
* Initialize the provider synchronously
|
|
34
|
+
* Initialize the provider synchronously with fallback mechanisms
|
|
35
|
+
* to handle conflicts between multiple wallet providers
|
|
34
36
|
*/
|
|
35
37
|
private initProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Get available Ethereum provider from multiple possible sources
|
|
40
|
+
*/
|
|
41
|
+
private getAvailableEthereumProvider;
|
|
36
42
|
/**
|
|
37
43
|
* Initialize the BrowserProvider (async method for explicit calls)
|
|
38
44
|
*/
|
|
@@ -84,7 +90,7 @@ declare class Web3Connector extends EventEmitter {
|
|
|
84
90
|
*/
|
|
85
91
|
private requestSignatureWithTimeout;
|
|
86
92
|
/**
|
|
87
|
-
* Checks if
|
|
93
|
+
* Checks if any Ethereum provider is available
|
|
88
94
|
*/
|
|
89
95
|
isAvailable(): boolean;
|
|
90
96
|
/**
|