shogun-core 3.3.7 → 4.0.0
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 +1378 -1221
- package/dist/browser/shogun-core.js +78074 -45286
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +2 -3
- package/dist/examples/simple-api-test.js +90 -65
- package/dist/examples/zkproof-credentials-example.js +218 -0
- package/dist/examples/zkproof-example.js +206 -0
- package/dist/gundb/api.js +111 -467
- package/dist/index.js +10 -1
- package/dist/interfaces/shogun.js +2 -2
- package/dist/managers/AuthManager.js +0 -2
- package/dist/managers/CoreInitializer.js +9 -12
- package/dist/plugins/index.js +9 -21
- package/dist/plugins/nostr/nostrConnectorPlugin.js +2 -2
- package/dist/plugins/webauthn/webauthn.js +20 -7
- package/dist/plugins/webauthn/webauthnPlugin.js +101 -17
- package/dist/plugins/zkproof/index.js +53 -0
- package/dist/plugins/zkproof/zkCredentials.js +213 -0
- package/dist/plugins/zkproof/zkProofConnector.js +198 -0
- package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
- package/dist/types/core.d.ts +1 -1
- package/dist/types/examples/simple-api-test.d.ts +6 -1
- package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- package/dist/types/gundb/api.d.ts +77 -165
- package/dist/types/gundb/types.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/interfaces/events.d.ts +3 -3
- package/dist/types/interfaces/shogun.d.ts +9 -24
- package/dist/types/plugins/index.d.ts +5 -3
- package/dist/types/plugins/webauthn/types.d.ts +22 -1
- package/dist/types/plugins/webauthn/webauthn.d.ts +1 -1
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +23 -2
- package/dist/types/plugins/zkproof/index.d.ts +48 -0
- package/dist/types/plugins/zkproof/types.d.ts +123 -0
- package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
- package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
- package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
- package/dist/types/utils/seedPhrase.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +2 -2
- package/dist/utils/seedPhrase.js +97 -0
- package/dist/utils/validation.js +3 -1
- package/package.json +14 -8
- package/dist/examples/api-test.js +0 -273
- package/dist/migration-test.js +0 -96
- package/dist/plugins/oauth/index.js +0 -8
- package/dist/plugins/oauth/oauthConnector.js +0 -759
- package/dist/plugins/oauth/oauthPlugin.js +0 -400
- package/dist/types/examples/api-test.d.ts +0 -12
- package/dist/types/migration-test.d.ts +0 -16
- 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/plugins/{oauth → zkproof}/types.js +0 -0
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simplified API layer
|
|
3
|
-
* Provides quick-start
|
|
2
|
+
* Simplified API layer focused on valuable helper methods.
|
|
3
|
+
* Provides quick-start initialization and high-level convenience methods.
|
|
4
|
+
*
|
|
5
|
+
* For basic operations (get, put, set, remove, auth), use DataBase directly.
|
|
6
|
+
* This class provides:
|
|
7
|
+
* - Quick initialization helpers (QuickStart, AutoQuickStart)
|
|
8
|
+
* - Array/Object conversion utilities for GunDB
|
|
9
|
+
* - High-level user data helpers (profile, settings, collections)
|
|
4
10
|
*/
|
|
5
|
-
import { GunMessageGet, GunMessagePut } from "gun";
|
|
6
11
|
import { DataBase } from "./db";
|
|
7
12
|
/**
|
|
8
|
-
* Simple API wrapper that provides
|
|
13
|
+
* Simple API wrapper that provides high-level helper methods.
|
|
14
|
+
* For basic operations, use the DataBase instance directly via the `database` property.
|
|
9
15
|
*/
|
|
10
16
|
export declare class SimpleGunAPI {
|
|
11
17
|
private db;
|
|
@@ -15,183 +21,40 @@ export declare class SimpleGunAPI {
|
|
|
15
21
|
*/
|
|
16
22
|
constructor(db: DataBase);
|
|
17
23
|
/**
|
|
18
|
-
* Get
|
|
19
|
-
*
|
|
20
|
-
* @returns The data at the path, or null if not found or on error.
|
|
24
|
+
* Get direct access to the DataBase instance for full control.
|
|
25
|
+
* Use this for basic operations like get, put, set, remove, login, etc.
|
|
21
26
|
*/
|
|
22
|
-
get
|
|
23
|
-
/**
|
|
24
|
-
* Get the Gun node at a given path for chaining operations.
|
|
25
|
-
* @param path The path to the node.
|
|
26
|
-
* @returns The Gun node.
|
|
27
|
-
*/
|
|
28
|
-
getNode(path: string): any;
|
|
29
|
-
/**
|
|
30
|
-
* Get the Gun node at a given path for direct chaining.
|
|
31
|
-
* @param path The path to the node.
|
|
32
|
-
* @returns The Gun node.
|
|
33
|
-
*/
|
|
34
|
-
node(path: string): any;
|
|
35
|
-
/**
|
|
36
|
-
* Get a chainable wrapper for a Gun node at a given path.
|
|
37
|
-
* @param path The path to the node.
|
|
38
|
-
* @returns An object with chainable methods: get, put, set, once, then, map.
|
|
39
|
-
*/
|
|
40
|
-
chain(path: string): {
|
|
41
|
-
get: (subPath: string) => GunMessageGet<any, any>;
|
|
42
|
-
put: (data: any) => Promise<GunMessagePut>;
|
|
43
|
-
set: (data: any) => Promise<GunMessagePut>;
|
|
44
|
-
once: () => Promise<any>;
|
|
45
|
-
then: () => Promise<any>;
|
|
46
|
-
map: (callback: (value: any, key: string) => any) => any;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Put data at a given path.
|
|
50
|
-
* @param path The path to put data to.
|
|
51
|
-
* @param data The data to put.
|
|
52
|
-
* @returns The GunMessagePut result.
|
|
53
|
-
*/
|
|
54
|
-
put<T = unknown>(path: string, data: T): Promise<GunMessagePut>;
|
|
55
|
-
/**
|
|
56
|
-
* Set data at a given path (alternative to put).
|
|
57
|
-
* @param path The path to set data to.
|
|
58
|
-
* @param data The data to set.
|
|
59
|
-
* @returns The GunMessagePut result.
|
|
60
|
-
*/
|
|
61
|
-
set<T = unknown>(path: string, data: T): Promise<GunMessagePut>;
|
|
62
|
-
/**
|
|
63
|
-
* Remove data at a given path.
|
|
64
|
-
* @param path The path to remove data from.
|
|
65
|
-
* @returns The GunMessagePut result.
|
|
66
|
-
*/
|
|
67
|
-
remove(path: string): Promise<GunMessagePut>;
|
|
68
|
-
/**
|
|
69
|
-
* Log in a user.
|
|
70
|
-
* @param username The username.
|
|
71
|
-
* @param password The password.
|
|
72
|
-
* @returns The user info if successful, or null.
|
|
73
|
-
*/
|
|
74
|
-
login(username: string, password: string): Promise<{
|
|
75
|
-
userPub: string;
|
|
76
|
-
username: string;
|
|
77
|
-
} | null>;
|
|
78
|
-
/**
|
|
79
|
-
* Sign up a new user.
|
|
80
|
-
* @param username The username.
|
|
81
|
-
* @param password The password.
|
|
82
|
-
* @returns The user info if successful, or null.
|
|
83
|
-
*/
|
|
84
|
-
signup(username: string, password: string): Promise<{
|
|
85
|
-
userPub: string;
|
|
86
|
-
username: string;
|
|
87
|
-
} | null>;
|
|
88
|
-
/**
|
|
89
|
-
* Log out the current user.
|
|
90
|
-
*/
|
|
91
|
-
logout(): void;
|
|
92
|
-
/**
|
|
93
|
-
* Check if a user is currently logged in.
|
|
94
|
-
* @returns True if logged in, false otherwise.
|
|
95
|
-
*/
|
|
96
|
-
isLoggedIn(): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Get user data at a given path (requires login).
|
|
99
|
-
* @param path The path to the user data.
|
|
100
|
-
* @returns The user data, or null if not found or on error.
|
|
101
|
-
*/
|
|
102
|
-
getUserData<T = unknown>(path: string): Promise<T | null>;
|
|
103
|
-
/**
|
|
104
|
-
* Put user data at a given path (requires login).
|
|
105
|
-
* @param path The path to put data to.
|
|
106
|
-
* @param data The data to put.
|
|
107
|
-
* @returns True if successful, false otherwise.
|
|
108
|
-
*/
|
|
109
|
-
putUserData<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
110
|
-
/**
|
|
111
|
-
* Set user data at a given path (alternative to put, requires login).
|
|
112
|
-
* @param path The path to set data to.
|
|
113
|
-
* @param data The data to set.
|
|
114
|
-
* @returns True if successful, false otherwise.
|
|
115
|
-
*/
|
|
116
|
-
setUserData<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
117
|
-
/**
|
|
118
|
-
* Remove user data at a given path (requires login).
|
|
119
|
-
* @param path The path to remove data from.
|
|
120
|
-
* @returns True if successful, false otherwise.
|
|
121
|
-
*/
|
|
122
|
-
removeUserData(path: string): Promise<boolean>;
|
|
27
|
+
get database(): DataBase;
|
|
123
28
|
/**
|
|
124
29
|
* Convert an array to an indexed object for GunDB storage.
|
|
30
|
+
* GunDB doesn't store arrays natively, so this converts them to objects indexed by ID.
|
|
125
31
|
* Example: [{id: '1', ...}, {id: '2', ...}] => { "1": {...}, "2": {...} }
|
|
126
|
-
* @param arr The array to convert.
|
|
127
|
-
* @returns The indexed object.
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
private getIndexedObjectFromArray;
|
|
131
|
-
/**
|
|
132
|
-
* Convert an indexed object back to an array.
|
|
133
|
-
* Example: { "1": {...}, "2": {...} } => [{id: '1', ...}, {id: '2', ...}]
|
|
134
|
-
* @param indexedObj The indexed object to convert.
|
|
135
|
-
* @returns The array.
|
|
136
|
-
* @private
|
|
137
|
-
*/
|
|
138
|
-
private getArrayFromIndexedObject;
|
|
139
|
-
/**
|
|
140
|
-
* Convert an array to an indexed object for GunDB storage (public method).
|
|
141
|
-
* @param arr The array to convert.
|
|
142
|
-
* @returns The indexed object.
|
|
32
|
+
* @param arr The array to convert (each item must have an 'id' property).
|
|
33
|
+
* @returns The indexed object suitable for GunDB storage.
|
|
143
34
|
*/
|
|
144
35
|
arrayToIndexedObject<T extends {
|
|
145
36
|
id: string | number;
|
|
146
37
|
}>(arr: T[]): Record<string, T>;
|
|
147
38
|
/**
|
|
148
|
-
* Convert an indexed object to an array
|
|
39
|
+
* Convert an indexed object back to an array.
|
|
40
|
+
* Reverses the arrayToIndexedObject conversion.
|
|
41
|
+
* Example: { "1": {...}, "2": {...} } => [{id: '1', ...}, {id: '2', ...}]
|
|
149
42
|
* @param indexedObj The indexed object to convert.
|
|
150
|
-
* @returns The array.
|
|
43
|
+
* @returns The array of items.
|
|
151
44
|
*/
|
|
152
45
|
indexedObjectToArray<T>(indexedObj: Record<string, T> | null): T[];
|
|
153
46
|
/**
|
|
154
|
-
* Get
|
|
155
|
-
*
|
|
156
|
-
* @
|
|
157
|
-
* @returns The Gun node.
|
|
158
|
-
* @throws If not logged in.
|
|
159
|
-
*/
|
|
160
|
-
getUserNode(path: string): any;
|
|
161
|
-
/**
|
|
162
|
-
* Get the GunDB global node at a given path.
|
|
163
|
-
* Useful for advanced operations that need direct GunDB node access.
|
|
164
|
-
* @param path The path to the global node.
|
|
165
|
-
* @returns The Gun node.
|
|
47
|
+
* Get all user data (returns user's entire data tree).
|
|
48
|
+
* Requires user to be logged in.
|
|
49
|
+
* @returns The complete user data tree, or null if not logged in or on error.
|
|
166
50
|
*/
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Get the current user info.
|
|
170
|
-
* @returns The current user info, or null if not logged in.
|
|
171
|
-
*/
|
|
172
|
-
getCurrentUser(): {
|
|
173
|
-
pub: string;
|
|
174
|
-
username?: string;
|
|
175
|
-
} | null;
|
|
176
|
-
/**
|
|
177
|
-
* Check if a user exists by alias.
|
|
178
|
-
* @param alias The user alias.
|
|
179
|
-
* @returns True if the user exists, false otherwise.
|
|
180
|
-
*/
|
|
181
|
-
userExists(alias: string): Promise<boolean>;
|
|
182
|
-
/**
|
|
183
|
-
* Get user info by alias.
|
|
184
|
-
* @param alias The user alias.
|
|
185
|
-
* @returns The user info, or null if not found.
|
|
186
|
-
*/
|
|
187
|
-
getUser(alias: string): Promise<{
|
|
188
|
-
userPub: string;
|
|
189
|
-
username: string;
|
|
190
|
-
} | null>;
|
|
51
|
+
getAllUserData(): Promise<Record<string, unknown> | null>;
|
|
191
52
|
/**
|
|
192
|
-
*
|
|
53
|
+
* Update user profile with common fields.
|
|
54
|
+
* Provides a standardized location for user profile data.
|
|
55
|
+
* @param profileData Profile data to save (name, email, bio, avatar, etc.)
|
|
56
|
+
* @returns True if successful, false otherwise.
|
|
193
57
|
*/
|
|
194
|
-
getAllUserData(): Promise<Record<string, unknown> | null>;
|
|
195
58
|
updateProfile(profileData: {
|
|
196
59
|
name?: string;
|
|
197
60
|
email?: string;
|
|
@@ -199,14 +62,63 @@ export declare class SimpleGunAPI {
|
|
|
199
62
|
avatar?: string;
|
|
200
63
|
[key: string]: unknown;
|
|
201
64
|
}): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Get user profile data.
|
|
67
|
+
* @returns The user profile data, or null if not found or not logged in.
|
|
68
|
+
*/
|
|
202
69
|
getProfile(): Promise<Record<string, unknown> | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Save user settings.
|
|
72
|
+
* Provides a standardized location for application settings.
|
|
73
|
+
* @param settings Settings object to save.
|
|
74
|
+
* @returns True if successful, false otherwise.
|
|
75
|
+
*/
|
|
203
76
|
saveSettings(settings: Record<string, unknown>): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Get user settings.
|
|
79
|
+
* @returns The user settings, or null if not found or not logged in.
|
|
80
|
+
*/
|
|
204
81
|
getSettings(): Promise<Record<string, unknown> | null>;
|
|
82
|
+
/**
|
|
83
|
+
* Save user preferences.
|
|
84
|
+
* Provides a standardized location for user preferences (distinct from settings).
|
|
85
|
+
* @param preferences Preferences object to save.
|
|
86
|
+
* @returns True if successful, false otherwise.
|
|
87
|
+
*/
|
|
205
88
|
savePreferences(preferences: Record<string, unknown>): Promise<boolean>;
|
|
89
|
+
/**
|
|
90
|
+
* Get user preferences.
|
|
91
|
+
* @returns The user preferences, or null if not found or not logged in.
|
|
92
|
+
*/
|
|
206
93
|
getPreferences(): Promise<Record<string, unknown> | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Create a user collection with initial items.
|
|
96
|
+
* Provides a standardized location for user collections.
|
|
97
|
+
* @param collectionName The name of the collection.
|
|
98
|
+
* @param items The initial items for the collection.
|
|
99
|
+
* @returns True if successful, false otherwise.
|
|
100
|
+
*/
|
|
207
101
|
createCollection<T = unknown>(collectionName: string, items: Record<string, T>): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Add an item to a user collection.
|
|
104
|
+
* @param collectionName The name of the collection.
|
|
105
|
+
* @param itemId The ID of the item to add.
|
|
106
|
+
* @param item The item data.
|
|
107
|
+
* @returns True if successful, false otherwise.
|
|
108
|
+
*/
|
|
208
109
|
addToCollection<T = unknown>(collectionName: string, itemId: string, item: T): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* Get a user collection.
|
|
112
|
+
* @param collectionName The name of the collection.
|
|
113
|
+
* @returns The collection data, or null if not found or not logged in.
|
|
114
|
+
*/
|
|
209
115
|
getCollection(collectionName: string): Promise<Record<string, unknown> | null>;
|
|
116
|
+
/**
|
|
117
|
+
* Remove an item from a user collection.
|
|
118
|
+
* @param collectionName The name of the collection.
|
|
119
|
+
* @param itemId The ID of the item to remove.
|
|
120
|
+
* @returns True if successful, false otherwise.
|
|
121
|
+
*/
|
|
210
122
|
removeFromCollection(collectionName: string, itemId: string): Promise<boolean>;
|
|
211
123
|
}
|
|
212
124
|
/**
|
|
@@ -240,7 +240,7 @@ export interface TypedGunError extends Error {
|
|
|
240
240
|
context?: Record<string, unknown>;
|
|
241
241
|
}
|
|
242
242
|
export type GunOperation = "get" | "put" | "set" | "remove" | "once" | "on" | "off";
|
|
243
|
-
export type GunAuthMethod = "password" | "pair" | "webauthn" | "web3" | "nostr";
|
|
243
|
+
export type GunAuthMethod = "password" | "pair" | "webauthn" | "web3" | "nostr" | "zkproof";
|
|
244
244
|
export interface TypedGunWrapper<T = Record<string, unknown>> {
|
|
245
245
|
gun: IGunInstance<any>;
|
|
246
246
|
user: IGunUserInstance | null;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export * from "./config/simplified-config";
|
|
|
11
11
|
export type * from "./interfaces/plugin";
|
|
12
12
|
export type { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions, TypedGunOperationResult, TypedAuthResult, };
|
|
13
13
|
export { Gun, ShogunCore, SEA, RxJS, crypto, derive, GunErrors, DataBase, SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, AutoQuickStart, autoQuickStart, };
|
|
14
|
+
export { generateSeedPhrase, validateSeedPhrase, mnemonicToSeed, seedToPassword, deriveCredentialsFromMnemonic, formatSeedPhrase, normalizeSeedPhrase, } from "./utils/seedPhrase";
|
|
@@ -4,13 +4,13 @@ import { EventEmitter } from "../utils/eventEmitter";
|
|
|
4
4
|
* @interface AuthEventData
|
|
5
5
|
* @property {string} [userPub] - The user's public key (optional)
|
|
6
6
|
* @property {string} [username] - Optional username
|
|
7
|
-
* @property {"password" | "webauthn" | "web3" | "nostr" | "
|
|
8
|
-
* @property {string} [provider] - Optional provider name
|
|
7
|
+
* @property {"password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair" } method - Authentication method used
|
|
8
|
+
* @property {string} [provider] - Optional provider name
|
|
9
9
|
*/
|
|
10
10
|
export interface AuthEventData {
|
|
11
11
|
userPub?: string;
|
|
12
12
|
username?: string;
|
|
13
|
-
method: "password" | "webauthn" | "web3" | "nostr" | "
|
|
13
|
+
method: "password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair";
|
|
14
14
|
provider?: string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -36,14 +36,14 @@ export declare enum CorePlugins {
|
|
|
36
36
|
Web3 = "web3",
|
|
37
37
|
/** Bitcoin wallet plugin */
|
|
38
38
|
Nostr = "nostr",
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/** Zero-Knowledge Proof plugin */
|
|
40
|
+
ZkProof = "zkproof"
|
|
41
41
|
}
|
|
42
|
-
export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "
|
|
42
|
+
export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair";
|
|
43
43
|
export interface AuthEventData {
|
|
44
44
|
userPub?: string;
|
|
45
45
|
username?: string;
|
|
46
|
-
method: "password" | "webauthn" | "web3" | "nostr" | "
|
|
46
|
+
method: "password" | "webauthn" | "web3" | "nostr" | "zkproof" | "pair";
|
|
47
47
|
provider?: string;
|
|
48
48
|
}
|
|
49
49
|
export interface AuthResult {
|
|
@@ -70,14 +70,6 @@ export interface AuthResult {
|
|
|
70
70
|
email?: string;
|
|
71
71
|
name?: string;
|
|
72
72
|
picture?: string;
|
|
73
|
-
oauth?: {
|
|
74
|
-
provider: string;
|
|
75
|
-
id: string;
|
|
76
|
-
email?: string;
|
|
77
|
-
name?: string;
|
|
78
|
-
picture?: string;
|
|
79
|
-
lastLogin: number;
|
|
80
|
-
};
|
|
81
73
|
};
|
|
82
74
|
}
|
|
83
75
|
/**
|
|
@@ -100,6 +92,7 @@ export interface SignUpResult {
|
|
|
100
92
|
epub: string;
|
|
101
93
|
epriv: string;
|
|
102
94
|
};
|
|
95
|
+
seedPhrase?: string;
|
|
103
96
|
redirectUrl?: string;
|
|
104
97
|
pendingAuth?: boolean;
|
|
105
98
|
provider?: string;
|
|
@@ -109,14 +102,6 @@ export interface SignUpResult {
|
|
|
109
102
|
email?: string;
|
|
110
103
|
name?: string;
|
|
111
104
|
picture?: string;
|
|
112
|
-
oauth?: {
|
|
113
|
-
provider: string;
|
|
114
|
-
id: string;
|
|
115
|
-
email?: string;
|
|
116
|
-
name?: string;
|
|
117
|
-
picture?: string;
|
|
118
|
-
lastLogin: number;
|
|
119
|
-
};
|
|
120
105
|
};
|
|
121
106
|
}
|
|
122
107
|
export interface IShogunCore extends PluginManager {
|
|
@@ -177,11 +162,11 @@ export interface ShogunCoreConfig {
|
|
|
177
162
|
nostr?: {
|
|
178
163
|
enabled?: boolean;
|
|
179
164
|
};
|
|
180
|
-
|
|
165
|
+
zkproof?: {
|
|
181
166
|
enabled?: boolean;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
167
|
+
defaultGroupId?: string;
|
|
168
|
+
deterministic?: boolean;
|
|
169
|
+
minEntropy?: number;
|
|
185
170
|
};
|
|
186
171
|
timeouts?: {
|
|
187
172
|
login?: number;
|
|
@@ -9,6 +9,8 @@ export type { Web3ConnectorPluginInterface } from "./web3/types";
|
|
|
9
9
|
export { NostrConnector } from "./nostr/nostrConnector";
|
|
10
10
|
export { NostrConnectorPlugin } from "./nostr/nostrConnectorPlugin";
|
|
11
11
|
export type { NostrConnectorPluginInterface, NostrConnectorCredentials, NostrConnectorKeyPair, NostrConnectorConfig, AlbyProvider, NostrProvider, } from "./nostr/types";
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export
|
|
12
|
+
export { ZkProofConnector } from "./zkproof/zkProofConnector";
|
|
13
|
+
export { ZkProofPlugin } from "./zkproof/zkProofPlugin";
|
|
14
|
+
export { ZkCredentials, CredentialType } from "./zkproof/zkCredentials";
|
|
15
|
+
export type { ZkProofPluginInterface, ZkIdentityData, ZkProofAuthResult, ZkProofGenerationOptions, ZkProofVerificationResult, ZkProofCredential, ZkProofConfig, SemaphoreProof, } from "./zkproof/types";
|
|
16
|
+
export type { CredentialClaim, VerifiableCredentialProof, CredentialVerificationResult, } from "./zkproof/zkCredentials";
|
|
@@ -148,9 +148,29 @@ export interface WebauthnPluginInterface {
|
|
|
148
148
|
/**
|
|
149
149
|
* Signup con WebAuthn
|
|
150
150
|
* @param username Nome utente
|
|
151
|
+
* @param options Optional signup options
|
|
151
152
|
* @returns Promise con il risultato dell'operazione
|
|
152
153
|
*/
|
|
153
|
-
signUp(username: string): Promise<SignUpResult>;
|
|
154
|
+
signUp(username: string, options?: WebAuthnSignUpOptions): Promise<SignUpResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Import account from seed phrase
|
|
157
|
+
* @param username Nome utente
|
|
158
|
+
* @param seedPhrase BIP39 mnemonic seed phrase (12 words)
|
|
159
|
+
* @returns Promise con il risultato dell'operazione
|
|
160
|
+
*/
|
|
161
|
+
importFromSeed(username: string, seedPhrase: string): Promise<SignUpResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Get seed phrase for current user (if available)
|
|
164
|
+
* @param username Nome utente
|
|
165
|
+
* @returns Seed phrase or null
|
|
166
|
+
*/
|
|
167
|
+
getSeedPhrase(username: string): Promise<string | null>;
|
|
168
|
+
}
|
|
169
|
+
export interface WebAuthnSignUpOptions {
|
|
170
|
+
/** Use existing seed phrase instead of generating new one */
|
|
171
|
+
seedPhrase?: string;
|
|
172
|
+
/** Generate and return seed phrase for multi-device support */
|
|
173
|
+
generateSeedPhrase?: boolean;
|
|
154
174
|
}
|
|
155
175
|
export interface WebAuthnUniformCredentials {
|
|
156
176
|
success: boolean;
|
|
@@ -159,4 +179,5 @@ export interface WebAuthnUniformCredentials {
|
|
|
159
179
|
credentialId: string;
|
|
160
180
|
publicKey?: ArrayBuffer | null;
|
|
161
181
|
error?: string;
|
|
182
|
+
seedPhrase?: string;
|
|
162
183
|
}
|
|
@@ -111,7 +111,7 @@ export declare class Webauthn extends EventEmitter {
|
|
|
111
111
|
sign(data: Record<string, unknown>): Promise<unknown>;
|
|
112
112
|
}
|
|
113
113
|
export type { WebAuthnCredentials, DeviceInfo, CredentialResult };
|
|
114
|
-
export declare function deriveWebauthnKeys(username: string,
|
|
114
|
+
export declare function deriveWebauthnKeys(username: string, credentialIdOrSeedPhrase: string, useSeedPhrase?: boolean): Promise<{
|
|
115
115
|
pub: string;
|
|
116
116
|
priv: string;
|
|
117
117
|
epub: string;
|
|
@@ -149,10 +149,31 @@ export declare class WebauthnPlugin extends BasePlugin implements WebauthnPlugin
|
|
|
149
149
|
* Register new user with WebAuthn
|
|
150
150
|
* This is the recommended method for WebAuthn registration
|
|
151
151
|
* @param username - Username
|
|
152
|
-
* @
|
|
152
|
+
* @param options - Optional signup options (seed phrase support)
|
|
153
|
+
* @returns {Promise<SignUpResult>} Registration result with optional seed phrase
|
|
153
154
|
* @description Creates a new user account using WebAuthn credentials.
|
|
154
155
|
* Requires browser support for WebAuthn.
|
|
156
|
+
* If generateSeedPhrase is true, returns a BIP39 mnemonic for multi-device support.
|
|
157
|
+
*/
|
|
158
|
+
signUp(username: string, options?: {
|
|
159
|
+
seedPhrase?: string;
|
|
160
|
+
generateSeedPhrase?: boolean;
|
|
161
|
+
}): Promise<SignUpResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Import existing account from seed phrase
|
|
164
|
+
* Allows accessing the same account across multiple devices
|
|
165
|
+
* @param username - Username
|
|
166
|
+
* @param seedPhrase - 12-word BIP39 mnemonic seed phrase
|
|
167
|
+
* @returns {Promise<SignUpResult>} Registration result
|
|
168
|
+
*/
|
|
169
|
+
importFromSeed(username: string, seedPhrase: string): Promise<SignUpResult>;
|
|
170
|
+
/**
|
|
171
|
+
* Get seed phrase for current user (if stored)
|
|
172
|
+
* Note: Seed phrases are NOT stored by default for security
|
|
173
|
+
* Users should save their seed phrase during registration
|
|
174
|
+
* @param username - Username
|
|
175
|
+
* @returns {Promise<string | null>} Seed phrase or null
|
|
155
176
|
*/
|
|
156
|
-
|
|
177
|
+
getSeedPhrase(username: string): Promise<string | null>;
|
|
157
178
|
}
|
|
158
179
|
export type { WebauthnPluginInterface } from "./types";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZK-Proof Plugin for Shogun Core
|
|
3
|
+
*
|
|
4
|
+
* Provides Zero-Knowledge Proof authentication using Semaphore protocol
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - Anonymous authentication without revealing identity
|
|
8
|
+
* - Multi-device support via trapdoor backup
|
|
9
|
+
* - Privacy-preserving group membership proofs
|
|
10
|
+
* - Compatible with Gun decentralized storage
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Initialize Shogun with ZK-Proof plugin
|
|
15
|
+
* const shogun = new ShogunCore({
|
|
16
|
+
* peers: ['https://gun-manhattan.herokuapp.com/gun'],
|
|
17
|
+
* zkproof: {
|
|
18
|
+
* enabled: true,
|
|
19
|
+
* defaultGroupId: 'my-app-users'
|
|
20
|
+
* }
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* await shogun.initialize();
|
|
24
|
+
*
|
|
25
|
+
* // Get the plugin
|
|
26
|
+
* const zkPlugin = shogun.getPlugin<ZkProofPlugin>('zkproof');
|
|
27
|
+
*
|
|
28
|
+
* // Sign up with ZK-Proof
|
|
29
|
+
* const signupResult = await zkPlugin.signUp();
|
|
30
|
+
* if (signupResult.success) {
|
|
31
|
+
* console.log('Trapdoor (save this!):', signupResult.seedPhrase);
|
|
32
|
+
* console.log('Public commitment:', signupResult.username);
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // Login with trapdoor
|
|
36
|
+
* const loginResult = await zkPlugin.login(trapdoor);
|
|
37
|
+
* if (loginResult.success) {
|
|
38
|
+
* console.log('Logged in anonymously!');
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @module zkproof
|
|
43
|
+
*/
|
|
44
|
+
export { ZkProofPlugin } from "./zkProofPlugin";
|
|
45
|
+
export { ZkProofConnector } from "./zkProofConnector";
|
|
46
|
+
export { ZkCredentials, CredentialType } from "./zkCredentials";
|
|
47
|
+
export type { ZkIdentityData, ZkProofAuthResult, ZkProofGenerationOptions, ZkProofVerificationResult, ZkProofCredential, ZkProofConfig, ZkProofPluginInterface, SemaphoreProof, } from "./types";
|
|
48
|
+
export type { CredentialClaim, VerifiableCredentialProof, CredentialVerificationResult, } from "./zkCredentials";
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ISEAPair } from "gun";
|
|
2
|
+
/**
|
|
3
|
+
* ZK-Proof identity data
|
|
4
|
+
*/
|
|
5
|
+
export interface ZkIdentityData {
|
|
6
|
+
/** Semaphore identity commitment (public) */
|
|
7
|
+
commitment: string;
|
|
8
|
+
/** Trapdoor (private - used for recovery/login) */
|
|
9
|
+
trapdoor?: string;
|
|
10
|
+
/** Nullifier (private) */
|
|
11
|
+
nullifier?: string;
|
|
12
|
+
/** Creation timestamp */
|
|
13
|
+
createdAt: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* ZK-Proof authentication result
|
|
17
|
+
*/
|
|
18
|
+
export interface ZkProofAuthResult {
|
|
19
|
+
success: boolean;
|
|
20
|
+
commitment?: string;
|
|
21
|
+
userPub?: string;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ZK-Proof generation options
|
|
26
|
+
*/
|
|
27
|
+
export interface ZkProofGenerationOptions {
|
|
28
|
+
/** Group ID for Semaphore group */
|
|
29
|
+
groupId?: string;
|
|
30
|
+
/** Custom message to prove */
|
|
31
|
+
message?: string;
|
|
32
|
+
/** Scope for the proof */
|
|
33
|
+
scope?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ZK-Proof verification result
|
|
37
|
+
*/
|
|
38
|
+
export interface ZkProofVerificationResult {
|
|
39
|
+
success: boolean;
|
|
40
|
+
verified: boolean;
|
|
41
|
+
commitment?: string;
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* ZK-Proof credential for Gun authentication
|
|
46
|
+
*/
|
|
47
|
+
export interface ZkProofCredential {
|
|
48
|
+
commitment: string;
|
|
49
|
+
gunPair: ISEAPair;
|
|
50
|
+
createdAt: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* ZK-Proof plugin configuration
|
|
54
|
+
*/
|
|
55
|
+
export interface ZkProofConfig {
|
|
56
|
+
/** Default group ID */
|
|
57
|
+
defaultGroupId?: string;
|
|
58
|
+
/** Enable deterministic identity generation */
|
|
59
|
+
deterministic?: boolean;
|
|
60
|
+
/** Minimum entropy for identity generation */
|
|
61
|
+
minEntropy?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* ZK-Proof plugin interface
|
|
65
|
+
*/
|
|
66
|
+
export interface ZkProofPluginInterface {
|
|
67
|
+
/**
|
|
68
|
+
* Generate a new ZK identity
|
|
69
|
+
* @param seed - Optional seed for deterministic generation
|
|
70
|
+
* @returns ZK identity data with trapdoor for backup
|
|
71
|
+
*/
|
|
72
|
+
generateIdentity(seed?: string): Promise<ZkIdentityData>;
|
|
73
|
+
/**
|
|
74
|
+
* Restore identity from trapdoor/seed phrase
|
|
75
|
+
* @param trapdoor - Trapdoor or seed phrase
|
|
76
|
+
* @returns ZK identity data
|
|
77
|
+
*/
|
|
78
|
+
restoreIdentity(trapdoor: string): Promise<ZkIdentityData>;
|
|
79
|
+
/**
|
|
80
|
+
* Generate credentials for Gun authentication
|
|
81
|
+
* @param identityData - ZK identity data
|
|
82
|
+
* @returns Gun SEA pair
|
|
83
|
+
*/
|
|
84
|
+
generateCredentials(identityData: ZkIdentityData): Promise<ISEAPair>;
|
|
85
|
+
/**
|
|
86
|
+
* Generate a zero-knowledge proof
|
|
87
|
+
* @param identityData - ZK identity data
|
|
88
|
+
* @param options - Proof generation options
|
|
89
|
+
* @returns Proof data
|
|
90
|
+
*/
|
|
91
|
+
generateProof(identityData: ZkIdentityData, options?: ZkProofGenerationOptions): Promise<any>;
|
|
92
|
+
/**
|
|
93
|
+
* Verify a zero-knowledge proof
|
|
94
|
+
* @param proof - Proof data to verify
|
|
95
|
+
* @param treeDepth - Merkle tree depth (default: 20)
|
|
96
|
+
* @returns Verification result
|
|
97
|
+
*/
|
|
98
|
+
verifyProof(proof: any, treeDepth?: number): Promise<ZkProofVerificationResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Login with ZK proof
|
|
101
|
+
* @param trapdoor - User's trapdoor/seed phrase
|
|
102
|
+
* @returns Authentication result
|
|
103
|
+
*/
|
|
104
|
+
login(trapdoor: string): Promise<ZkProofAuthResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Sign up with new ZK identity
|
|
107
|
+
* @param seed - Optional seed for deterministic generation
|
|
108
|
+
* @returns Authentication result with trapdoor for backup
|
|
109
|
+
*/
|
|
110
|
+
signUp(seed?: string): Promise<ZkProofAuthResult & {
|
|
111
|
+
trapdoor?: string;
|
|
112
|
+
}>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Semaphore proof data structure
|
|
116
|
+
*/
|
|
117
|
+
export interface SemaphoreProof {
|
|
118
|
+
merkleTreeRoot: string;
|
|
119
|
+
nullifierHash: string;
|
|
120
|
+
signal: string;
|
|
121
|
+
externalNullifier: string;
|
|
122
|
+
proof: string[];
|
|
123
|
+
}
|