shogun-core 3.0.4 → 3.0.6
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/dist/browser/shogun-core.js +91002 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +230 -0
- package/dist/core.js +338 -0
- package/dist/gundb/crypto.js +268 -0
- package/dist/gundb/db.js +1829 -0
- package/dist/gundb/derive.js +229 -0
- package/dist/gundb/errors.js +66 -0
- package/dist/gundb/index.js +6 -0
- package/dist/gundb/rxjs.js +445 -0
- package/dist/gundb/simple-api.js +438 -0
- package/dist/gundb/types.js +4 -0
- package/dist/index.js +16 -0
- package/dist/interfaces/common.js +1 -0
- package/dist/interfaces/events.js +36 -0
- package/dist/interfaces/plugin.js +1 -0
- package/dist/interfaces/shogun.js +34 -0
- package/dist/managers/AuthManager.js +225 -0
- package/dist/managers/CoreInitializer.js +227 -0
- package/dist/managers/EventManager.js +67 -0
- package/dist/managers/PluginManager.js +296 -0
- package/dist/migration-test.js +91 -0
- package/dist/plugins/base.js +47 -0
- package/dist/plugins/index.js +15 -0
- package/dist/plugins/nostr/index.js +4 -0
- package/dist/plugins/nostr/nostrConnector.js +413 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +446 -0
- package/dist/plugins/nostr/nostrSigner.js +313 -0
- package/dist/plugins/nostr/types.js +1 -0
- package/dist/plugins/oauth/index.js +3 -0
- package/dist/plugins/oauth/oauthConnector.js +753 -0
- package/dist/plugins/oauth/oauthPlugin.js +396 -0
- package/dist/plugins/oauth/types.js +1 -0
- package/dist/plugins/web3/index.js +4 -0
- package/dist/plugins/web3/types.js +1 -0
- package/dist/plugins/web3/web3Connector.js +528 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +448 -0
- package/dist/plugins/web3/web3Signer.js +308 -0
- package/dist/plugins/webauthn/index.js +3 -0
- package/dist/plugins/webauthn/types.js +11 -0
- package/dist/plugins/webauthn/webauthn.js +478 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +398 -0
- package/dist/plugins/webauthn/webauthnSigner.js +304 -0
- package/dist/storage/storage.js +147 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +401 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/simple-api.d.ts +90 -0
- package/dist/types/gundb/types.d.ts +264 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +215 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/migration-test.d.ts +16 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +14 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/oauth/index.d.ts +3 -0
- package/dist/types/plugins/oauth/oauthConnector.d.ts +110 -0
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +91 -0
- package/dist/types/plugins/oauth/types.d.ts +114 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +162 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +158 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/storage/storage.d.ts +50 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +241 -0
- package/dist/utils/eventEmitter.js +76 -0
- package/dist/utils/validation.js +72 -0
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { EventEmitter } from "../../utils/eventEmitter";
|
|
2
|
+
import { ConnectionResult, 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
|
+
export declare const MESSAGE_TO_SIGN = "I Love Shogun!";
|
|
11
|
+
/**
|
|
12
|
+
* Class for Bitcoin wallet connections and operations
|
|
13
|
+
*/
|
|
14
|
+
declare class NostrConnector extends EventEmitter {
|
|
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
|
+
* Clear signature cache for a specific address or all addresses
|
|
28
|
+
*/
|
|
29
|
+
clearSignatureCache(address?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Check if Nostr extension is available
|
|
32
|
+
*/
|
|
33
|
+
isNostrExtensionAvailable(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if any Bitcoin wallet is available
|
|
36
|
+
*/
|
|
37
|
+
isAvailable(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Connect to a wallet type
|
|
40
|
+
*/
|
|
41
|
+
connectWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Connect to Nostr extension
|
|
44
|
+
*/
|
|
45
|
+
private connectNostr;
|
|
46
|
+
/**
|
|
47
|
+
* Set up manual key pair for connection
|
|
48
|
+
*/
|
|
49
|
+
private connectManual;
|
|
50
|
+
/**
|
|
51
|
+
* Set a manual key pair for use
|
|
52
|
+
*/
|
|
53
|
+
setKeyPair(keyPair: NostrConnectorKeyPair): void;
|
|
54
|
+
/**
|
|
55
|
+
* Generate credentials using Nostr: username deterministico e chiave GunDB derivata dall'address
|
|
56
|
+
*/
|
|
57
|
+
generateCredentials(address: string, signature: string, message: string): Promise<{
|
|
58
|
+
username: string;
|
|
59
|
+
key: {
|
|
60
|
+
pub: string;
|
|
61
|
+
priv: string;
|
|
62
|
+
epub: string;
|
|
63
|
+
epriv: string;
|
|
64
|
+
secp256k1Bitcoin: {
|
|
65
|
+
privateKey: string;
|
|
66
|
+
publicKey: string;
|
|
67
|
+
address: string;
|
|
68
|
+
};
|
|
69
|
+
secp256k1Ethereum: {
|
|
70
|
+
privateKey: string;
|
|
71
|
+
publicKey: string;
|
|
72
|
+
address: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
message: string;
|
|
76
|
+
signature: string;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Generate a password from a signature
|
|
80
|
+
*/
|
|
81
|
+
generatePassword(signature: string): Promise<string>;
|
|
82
|
+
/**
|
|
83
|
+
* Verify a signature
|
|
84
|
+
*/
|
|
85
|
+
verifySignature(message: string, signature: string, address: any): Promise<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Get the currently connected address
|
|
88
|
+
*/
|
|
89
|
+
getConnectedAddress(): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Get the currently connected wallet type
|
|
92
|
+
*/
|
|
93
|
+
getConnectedType(): "alby" | "nostr" | "manual" | null;
|
|
94
|
+
/**
|
|
95
|
+
* Request a signature from the connected wallet
|
|
96
|
+
*/
|
|
97
|
+
requestSignature(address: string, message: string): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Cleanup event listeners
|
|
100
|
+
*/
|
|
101
|
+
cleanup(): void;
|
|
102
|
+
}
|
|
103
|
+
export declare function deriveNostrKeys(address: string, signature: string, message: string): Promise<{
|
|
104
|
+
pub: string;
|
|
105
|
+
priv: string;
|
|
106
|
+
epub: string;
|
|
107
|
+
epriv: string;
|
|
108
|
+
secp256k1Bitcoin: {
|
|
109
|
+
privateKey: string;
|
|
110
|
+
publicKey: string;
|
|
111
|
+
address: string;
|
|
112
|
+
};
|
|
113
|
+
secp256k1Ethereum: {
|
|
114
|
+
privateKey: string;
|
|
115
|
+
publicKey: string;
|
|
116
|
+
address: string;
|
|
117
|
+
};
|
|
118
|
+
}>;
|
|
119
|
+
export { NostrConnector };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { BasePlugin } from "../base";
|
|
2
|
+
import { ShogunCore } from "../../core";
|
|
3
|
+
import { NostrSigningCredential } from "./nostrSigner";
|
|
4
|
+
import { NostrConnectorCredentials, ConnectionResult, NostrConnectorPluginInterface } from "./types";
|
|
5
|
+
import { AuthResult, SignUpResult } from "../../interfaces/shogun";
|
|
6
|
+
/**
|
|
7
|
+
* Plugin for managing Bitcoin wallet functionality in ShogunCore
|
|
8
|
+
* Supports Alby, Nostr extensions, or direct key management
|
|
9
|
+
*/
|
|
10
|
+
export declare class NostrConnectorPlugin extends BasePlugin implements NostrConnectorPluginInterface {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
description: string;
|
|
14
|
+
private bitcoinConnector;
|
|
15
|
+
private signer;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritdoc
|
|
18
|
+
*/
|
|
19
|
+
initialize(core: ShogunCore): void;
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc
|
|
22
|
+
*/
|
|
23
|
+
destroy(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Ensure that the Bitcoin wallet module is initialized
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
private assertBitcoinConnector;
|
|
29
|
+
/**
|
|
30
|
+
* Assicura che il signer sia inizializzato
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private assertSigner;
|
|
34
|
+
/**
|
|
35
|
+
* @inheritdoc
|
|
36
|
+
*/
|
|
37
|
+
isAvailable(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if Nostr extension is available
|
|
40
|
+
*/
|
|
41
|
+
isNostrExtensionAvailable(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Connect to Nostr wallet automatically
|
|
44
|
+
* This is a convenience method for easy wallet connection
|
|
45
|
+
*/
|
|
46
|
+
connectNostrWallet(): Promise<ConnectionResult>;
|
|
47
|
+
/**
|
|
48
|
+
* @inheritdoc
|
|
49
|
+
*/
|
|
50
|
+
connectBitcoinWallet(type?: "alby" | "nostr" | "manual"): Promise<ConnectionResult>;
|
|
51
|
+
/**
|
|
52
|
+
* @inheritdoc
|
|
53
|
+
*/
|
|
54
|
+
generateCredentials(address: string, signature: string, message: string): Promise<NostrConnectorCredentials>;
|
|
55
|
+
/**
|
|
56
|
+
* @inheritdoc
|
|
57
|
+
*/
|
|
58
|
+
cleanup(): void;
|
|
59
|
+
/**
|
|
60
|
+
* @inheritdoc
|
|
61
|
+
*/
|
|
62
|
+
verifySignature(message: string, signature: string, address: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* @inheritdoc
|
|
65
|
+
*/
|
|
66
|
+
generatePassword(signature: string): Promise<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new Nostr signing credential
|
|
69
|
+
* CONSISTENT with normal Nostr approach
|
|
70
|
+
*/
|
|
71
|
+
createSigningCredential(address: string): Promise<NostrSigningCredential>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates an authenticator function for Nostr signing
|
|
74
|
+
*/
|
|
75
|
+
createAuthenticator(address: string): (data: any) => Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a derived key pair from Nostr credential
|
|
78
|
+
*/
|
|
79
|
+
createDerivedKeyPair(address: string, extra?: string[]): Promise<{
|
|
80
|
+
pub: string;
|
|
81
|
+
priv: string;
|
|
82
|
+
epub: string;
|
|
83
|
+
epriv: string;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Signs data with derived keys after Nostr verification
|
|
87
|
+
*/
|
|
88
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Get signing credential by address
|
|
91
|
+
*/
|
|
92
|
+
getSigningCredential(address: string): NostrSigningCredential | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* List all signing credentials
|
|
95
|
+
*/
|
|
96
|
+
listSigningCredentials(): NostrSigningCredential[];
|
|
97
|
+
/**
|
|
98
|
+
* Remove a signing credential
|
|
99
|
+
*/
|
|
100
|
+
removeSigningCredential(address: string): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a Gun user from Nostr signing credential
|
|
103
|
+
* This ensures the SAME user is created as with normal approach
|
|
104
|
+
*/
|
|
105
|
+
createGunUserFromSigningCredential(address: string): Promise<{
|
|
106
|
+
success: boolean;
|
|
107
|
+
userPub?: string;
|
|
108
|
+
error?: string;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* Get the Gun user public key for a signing credential
|
|
112
|
+
*/
|
|
113
|
+
getGunUserPubFromSigningCredential(address: string): string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Get the password (for consistency checking)
|
|
116
|
+
*/
|
|
117
|
+
getPassword(address: string): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Verify consistency between oneshot and normal approaches
|
|
120
|
+
* This ensures both approaches create the same Gun user
|
|
121
|
+
*/
|
|
122
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
123
|
+
consistent: boolean;
|
|
124
|
+
actualUserPub?: string;
|
|
125
|
+
expectedUserPub?: string;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
129
|
+
* This is the recommended method for oneshot signing with full consistency
|
|
130
|
+
*/
|
|
131
|
+
setupConsistentOneshotSigning(address: string): Promise<{
|
|
132
|
+
credential: NostrSigningCredential;
|
|
133
|
+
authenticator: (data: any) => Promise<string>;
|
|
134
|
+
gunUser: {
|
|
135
|
+
success: boolean;
|
|
136
|
+
userPub?: string;
|
|
137
|
+
error?: string;
|
|
138
|
+
};
|
|
139
|
+
username: string;
|
|
140
|
+
password: string;
|
|
141
|
+
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Login with Bitcoin wallet
|
|
144
|
+
* @param address - Bitcoin address
|
|
145
|
+
* @returns {Promise<AuthResult>} Authentication result
|
|
146
|
+
* @description Authenticates the user using Bitcoin wallet credentials after signature verification
|
|
147
|
+
*/
|
|
148
|
+
login(address: string): Promise<AuthResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Register new user with Nostr wallet
|
|
151
|
+
* @param address - Nostr address
|
|
152
|
+
* @returns {Promise<SignUpResult>} Registration result
|
|
153
|
+
*/
|
|
154
|
+
signUp(address: string): Promise<SignUpResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Convenience method that matches the interface pattern
|
|
157
|
+
*/
|
|
158
|
+
loginWithBitcoinWallet(address: string): Promise<AuthResult>;
|
|
159
|
+
/**
|
|
160
|
+
* Convenience method that matches the interface pattern
|
|
161
|
+
*/
|
|
162
|
+
signUpWithBitcoinWallet(address: string): Promise<AuthResult>;
|
|
163
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
* FIX: Use derived pair instead of username/password for GunDB auth
|
|
63
|
+
*/
|
|
64
|
+
createGunUser(address: string, gunInstance: any): Promise<{
|
|
65
|
+
success: boolean;
|
|
66
|
+
userPub?: string;
|
|
67
|
+
error?: string;
|
|
68
|
+
}>;
|
|
69
|
+
/**
|
|
70
|
+
* Signs data using Nostr + derived keys
|
|
71
|
+
* This provides a hybrid approach: Nostr for user verification + derived keys for actual signing
|
|
72
|
+
* CONSISTENT with normal approach
|
|
73
|
+
*/
|
|
74
|
+
signWithDerivedKeys(data: any, address: string, extra?: string[]): Promise<string>;
|
|
75
|
+
/**
|
|
76
|
+
* Get the Gun user public key for a credential
|
|
77
|
+
* This allows checking if the same user would be created
|
|
78
|
+
*/
|
|
79
|
+
getGunUserPub(address: string): string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get the password (for consistency checking)
|
|
82
|
+
*/
|
|
83
|
+
getPassword(address: string): string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Check if this credential would create the same Gun user as normal approach
|
|
86
|
+
*/
|
|
87
|
+
verifyConsistency(address: string, expectedUserPub?: string): Promise<{
|
|
88
|
+
consistent: boolean;
|
|
89
|
+
actualUserPub?: string;
|
|
90
|
+
expectedUserPub?: string;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Get credential by address
|
|
94
|
+
*/
|
|
95
|
+
getCredential(address: string): NostrSigningCredential | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* List all stored credentials
|
|
98
|
+
*/
|
|
99
|
+
listCredentials(): NostrSigningCredential[];
|
|
100
|
+
/**
|
|
101
|
+
* Remove a credential
|
|
102
|
+
*/
|
|
103
|
+
removeCredential(address: string): boolean;
|
|
104
|
+
}
|
|
105
|
+
export default NostrSigner;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { BaseConfig, BaseResult, BaseCacheEntry } from "../../interfaces/common";
|
|
2
|
+
import { AuthResult, SignUpResult } from "../../interfaces/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
|
+
/** Chiave GunDB derivata dalla signature */
|
|
19
|
+
key: any;
|
|
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, signature: string, message: 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
|
+
* Sign up with Nostr wallet
|
|
118
|
+
* @param address Nostr address
|
|
119
|
+
* @returns Promise with authentication result
|
|
120
|
+
*/
|
|
121
|
+
signUp(address: string): Promise<SignUpResult>;
|
|
122
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Connector - Secure version for GunDB user creation
|
|
3
|
+
*/
|
|
4
|
+
import { EventEmitter } from "../../utils/eventEmitter";
|
|
5
|
+
import { OAuthConfig, OAuthProvider, OAuthUserInfo, OAuthCredentials, OAuthConnectionResult } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* OAuth Connector
|
|
8
|
+
*/
|
|
9
|
+
export declare class OAuthConnector extends EventEmitter {
|
|
10
|
+
private readonly DEFAULT_CONFIG;
|
|
11
|
+
private config;
|
|
12
|
+
private readonly userCache;
|
|
13
|
+
private readonly memoryStorage;
|
|
14
|
+
constructor(config?: Partial<OAuthConfig>);
|
|
15
|
+
/**
|
|
16
|
+
* Validates security configuration
|
|
17
|
+
*/
|
|
18
|
+
private validateSecurityConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Update the connector configuration
|
|
21
|
+
* @param config - New configuration options
|
|
22
|
+
*/
|
|
23
|
+
updateConfig(config: Partial<OAuthConfig>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get origin URL (browser or Node.js compatible)
|
|
26
|
+
*/
|
|
27
|
+
private getOrigin;
|
|
28
|
+
/**
|
|
29
|
+
* Storage abstraction (browser sessionStorage or Node.js Map)
|
|
30
|
+
*/
|
|
31
|
+
private setItem;
|
|
32
|
+
private getItem;
|
|
33
|
+
private removeItem;
|
|
34
|
+
/**
|
|
35
|
+
* Check if OAuth is supported
|
|
36
|
+
*/
|
|
37
|
+
isSupported(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get available OAuth providers
|
|
40
|
+
*/
|
|
41
|
+
getAvailableProviders(): OAuthProvider[];
|
|
42
|
+
/**
|
|
43
|
+
* Generate PKCE challenge for secure OAuth flow
|
|
44
|
+
*/
|
|
45
|
+
private generatePKCEChallenge;
|
|
46
|
+
/**
|
|
47
|
+
* Calculate the PKCE code challenge from a code verifier.
|
|
48
|
+
* Hashes the verifier using SHA-256 and then base64url encodes it.
|
|
49
|
+
* @param verifier The code verifier string.
|
|
50
|
+
* @returns The base64url-encoded SHA-256 hash of the verifier.
|
|
51
|
+
*/
|
|
52
|
+
private calculatePKCECodeChallenge;
|
|
53
|
+
/**
|
|
54
|
+
* Encodes a buffer into a Base64URL-encoded string.
|
|
55
|
+
* @param buffer The buffer to encode.
|
|
56
|
+
* @returns The Base64URL-encoded string.
|
|
57
|
+
*/
|
|
58
|
+
private base64urlEncode;
|
|
59
|
+
/**
|
|
60
|
+
* Generate cryptographically secure random string
|
|
61
|
+
*/
|
|
62
|
+
private generateRandomString;
|
|
63
|
+
/**
|
|
64
|
+
* Initiate OAuth flow
|
|
65
|
+
*/
|
|
66
|
+
initiateOAuth(provider: OAuthProvider): Promise<OAuthConnectionResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Complete OAuth flow
|
|
69
|
+
*/
|
|
70
|
+
completeOAuth(provider: OAuthProvider, authCode: string, state?: string): Promise<OAuthConnectionResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Generate credentials from OAuth user info
|
|
73
|
+
* Ora restituisce anche la chiave GunDB derivata (key)
|
|
74
|
+
*/
|
|
75
|
+
generateCredentials(userInfo: OAuthUserInfo, provider: OAuthProvider): Promise<OAuthCredentials & {
|
|
76
|
+
key: any;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Exchange authorization code for access token
|
|
80
|
+
*/
|
|
81
|
+
private exchangeCodeForToken;
|
|
82
|
+
/**
|
|
83
|
+
* Fetch user info from provider
|
|
84
|
+
*/
|
|
85
|
+
private fetchUserInfo;
|
|
86
|
+
/**
|
|
87
|
+
* Normalize user info from different providers
|
|
88
|
+
*/
|
|
89
|
+
private normalizeUserInfo;
|
|
90
|
+
/**
|
|
91
|
+
* Cache user info
|
|
92
|
+
*/
|
|
93
|
+
private cacheUserInfo;
|
|
94
|
+
/**
|
|
95
|
+
* Get cached user info
|
|
96
|
+
*/
|
|
97
|
+
getCachedUserInfo(userId: string, provider: OAuthProvider): OAuthUserInfo | null;
|
|
98
|
+
/**
|
|
99
|
+
* Clear user cache
|
|
100
|
+
*/
|
|
101
|
+
clearUserCache(userId?: string, provider?: OAuthProvider): void;
|
|
102
|
+
/**
|
|
103
|
+
* Cleanup
|
|
104
|
+
*/
|
|
105
|
+
cleanup(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Clean up expired OAuth data from storage
|
|
108
|
+
*/
|
|
109
|
+
private cleanupExpiredOAuthData;
|
|
110
|
+
}
|