shogun-core 3.3.8 → 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 -1176
- package/dist/browser/shogun-core.js +78019 -44874
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +1 -1
- package/dist/examples/zkproof-credentials-example.js +218 -0
- package/dist/examples/zkproof-example.js +206 -0
- 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/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- 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 -1
- 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/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
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZkProofPlugin = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const zkProofConnector_1 = require("./zkProofConnector");
|
|
6
|
+
const shogun_1 = require("../../interfaces/shogun");
|
|
7
|
+
const errorHandler_1 = require("../../utils/errorHandler");
|
|
8
|
+
/**
|
|
9
|
+
* Plugin for Zero-Knowledge Proof authentication using Semaphore protocol
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Anonymous authentication with ZK proofs
|
|
13
|
+
* - Multi-device support via trapdoor backup
|
|
14
|
+
* - Privacy-preserving identity management
|
|
15
|
+
* - Compatible with Gun decentralized storage
|
|
16
|
+
*/
|
|
17
|
+
class ZkProofPlugin extends base_1.BasePlugin {
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
super();
|
|
20
|
+
this.name = "zkproof";
|
|
21
|
+
this.version = "1.0.0";
|
|
22
|
+
this.description = "Zero-Knowledge Proof authentication using Semaphore protocol for ShogunCore";
|
|
23
|
+
this._category = shogun_1.PluginCategory.Authentication;
|
|
24
|
+
this.connector = null;
|
|
25
|
+
this.config = {
|
|
26
|
+
defaultGroupId: "shogun-users",
|
|
27
|
+
deterministic: false,
|
|
28
|
+
minEntropy: 128,
|
|
29
|
+
...config,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Initialize the plugin
|
|
34
|
+
*/
|
|
35
|
+
initialize(core) {
|
|
36
|
+
super.initialize(core);
|
|
37
|
+
this.connector = new zkProofConnector_1.ZkProofConnector();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Clean up resources
|
|
41
|
+
*/
|
|
42
|
+
destroy() {
|
|
43
|
+
if (this.connector) {
|
|
44
|
+
this.connector.cleanup();
|
|
45
|
+
}
|
|
46
|
+
this.connector = null;
|
|
47
|
+
super.destroy();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ensure connector is initialized
|
|
51
|
+
*/
|
|
52
|
+
assertConnector() {
|
|
53
|
+
this.assertInitialized();
|
|
54
|
+
if (!this.connector) {
|
|
55
|
+
throw new Error("ZK-Proof connector not initialized");
|
|
56
|
+
}
|
|
57
|
+
return this.connector;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generate a new ZK identity
|
|
61
|
+
*/
|
|
62
|
+
async generateIdentity(seed) {
|
|
63
|
+
try {
|
|
64
|
+
return await this.assertConnector().generateIdentity(seed);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENCRYPTION, "ZK_IDENTITY_GENERATION_FAILED", `Failed to generate ZK identity: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Restore identity from trapdoor/seed phrase
|
|
72
|
+
*/
|
|
73
|
+
async restoreIdentity(trapdoor) {
|
|
74
|
+
try {
|
|
75
|
+
if (!trapdoor || trapdoor.trim().length === 0) {
|
|
76
|
+
throw new Error("Trapdoor is required");
|
|
77
|
+
}
|
|
78
|
+
return await this.assertConnector().restoreIdentity(trapdoor);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENCRYPTION, "ZK_IDENTITY_RESTORE_FAILED", `Failed to restore ZK identity: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate credentials for Gun authentication
|
|
86
|
+
*/
|
|
87
|
+
async generateCredentials(identityData) {
|
|
88
|
+
try {
|
|
89
|
+
return await this.assertConnector().generateCredentials(identityData);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENCRYPTION, "ZK_CREDENTIAL_GENERATION_FAILED", `Failed to generate credentials: ${error.message}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Generate a zero-knowledge proof
|
|
97
|
+
*/
|
|
98
|
+
async generateProof(identityData, options) {
|
|
99
|
+
try {
|
|
100
|
+
return await this.assertConnector().generateProof(identityData, options);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENCRYPTION, "ZK_PROOF_GENERATION_FAILED", `Failed to generate ZK proof: ${error.message}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Verify a zero-knowledge proof
|
|
108
|
+
*/
|
|
109
|
+
async verifyProof(proof, treeDepth = 20) {
|
|
110
|
+
try {
|
|
111
|
+
return await this.assertConnector().verifyProof(proof, treeDepth);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
return {
|
|
115
|
+
success: false,
|
|
116
|
+
verified: false,
|
|
117
|
+
error: error.message,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Add identity to a group
|
|
123
|
+
*/
|
|
124
|
+
addToGroup(commitment, groupId) {
|
|
125
|
+
const group = groupId || this.config.defaultGroupId || "default";
|
|
126
|
+
this.assertConnector().addToGroup(commitment, group);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Login with ZK proof
|
|
130
|
+
* @param trapdoor - User's trapdoor/seed phrase
|
|
131
|
+
* @returns Authentication result
|
|
132
|
+
*/
|
|
133
|
+
async login(trapdoor) {
|
|
134
|
+
try {
|
|
135
|
+
const core = this.assertInitialized();
|
|
136
|
+
const connector = this.assertConnector();
|
|
137
|
+
if (!trapdoor || trapdoor.trim().length === 0) {
|
|
138
|
+
throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "TRAPDOOR_REQUIRED", "Trapdoor is required for ZK-Proof login");
|
|
139
|
+
}
|
|
140
|
+
console.log("🔐 ZK-Proof login - restoring identity from trapdoor");
|
|
141
|
+
// Restore identity from trapdoor
|
|
142
|
+
const identityData = await connector.restoreIdentity(trapdoor);
|
|
143
|
+
console.log(`🔐 ZK-Proof login - identity restored, commitment: ${identityData.commitment.slice(0, 16)}...`);
|
|
144
|
+
// Generate credentials for Gun
|
|
145
|
+
const gunPair = await connector.generateCredentials(identityData);
|
|
146
|
+
console.log(`🔐 ZK-Proof login - Gun credentials generated, pub: ${gunPair.pub.slice(0, 16)}...`);
|
|
147
|
+
// Authenticate with Gun using the derived pair via ShogunCore
|
|
148
|
+
const username = `zk_${identityData.commitment.slice(0, 16)}`;
|
|
149
|
+
try {
|
|
150
|
+
// Try to authenticate with existing account using ShogunCore
|
|
151
|
+
const loginResult = await core.loginWithPair(username, gunPair);
|
|
152
|
+
if (!loginResult.success) {
|
|
153
|
+
console.log("🔐 ZK-Proof login - existing account not found, this might be first login");
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
console.log("🔐 ZK-Proof login - Gun authentication successful");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (authError) {
|
|
160
|
+
console.log("🔐 ZK-Proof login - existing account not found, this might be first login");
|
|
161
|
+
}
|
|
162
|
+
// Set authentication method
|
|
163
|
+
core.setAuthMethod("zkproof");
|
|
164
|
+
// Add to default group
|
|
165
|
+
this.addToGroup(identityData.commitment);
|
|
166
|
+
const result = {
|
|
167
|
+
success: true,
|
|
168
|
+
userPub: gunPair.pub,
|
|
169
|
+
username: username,
|
|
170
|
+
authMethod: "zkproof",
|
|
171
|
+
sea: {
|
|
172
|
+
pub: gunPair.pub,
|
|
173
|
+
priv: gunPair.priv,
|
|
174
|
+
epub: gunPair.epub,
|
|
175
|
+
epriv: gunPair.epriv,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
// Emit login event
|
|
179
|
+
core.emit("auth:login", {
|
|
180
|
+
userPub: gunPair.pub,
|
|
181
|
+
username: username,
|
|
182
|
+
method: "zkproof",
|
|
183
|
+
});
|
|
184
|
+
console.log("🔐 ZK-Proof login - complete");
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
189
|
+
const errorCode = error?.code || "ZK_LOGIN_ERROR";
|
|
190
|
+
const errorMessage = error?.message || "Unknown error during ZK-Proof login";
|
|
191
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
192
|
+
return { success: false, error: errorMessage };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Sign up with new ZK identity
|
|
197
|
+
* @param seed - Optional seed for deterministic generation
|
|
198
|
+
* @returns Authentication result with trapdoor for backup
|
|
199
|
+
*/
|
|
200
|
+
async signUp(seed) {
|
|
201
|
+
try {
|
|
202
|
+
const core = this.assertInitialized();
|
|
203
|
+
const connector = this.assertConnector();
|
|
204
|
+
console.log("🔐 ZK-Proof signup - generating new identity");
|
|
205
|
+
// Generate new identity
|
|
206
|
+
const identityData = await connector.generateIdentity(seed);
|
|
207
|
+
console.log(`🔐 ZK-Proof signup - identity generated, commitment: ${identityData.commitment.slice(0, 16)}...`);
|
|
208
|
+
// Generate credentials for Gun
|
|
209
|
+
const gunPair = await connector.generateCredentials(identityData);
|
|
210
|
+
console.log(`🔐 ZK-Proof signup - Gun credentials generated, pub: ${gunPair.pub.slice(0, 16)}...`);
|
|
211
|
+
// Create Gun user account using ShogunCore methods
|
|
212
|
+
const username = `zk_${identityData.commitment.slice(0, 16)}`;
|
|
213
|
+
try {
|
|
214
|
+
// Try to create user with signUp
|
|
215
|
+
const signUpResult = await core.signUp(username, undefined, gunPair);
|
|
216
|
+
if (!signUpResult.success) {
|
|
217
|
+
// If user already exists, login with the pair
|
|
218
|
+
const loginResult = await core.loginWithPair(username, gunPair);
|
|
219
|
+
if (!loginResult.success) {
|
|
220
|
+
throw new Error(loginResult.error || "Failed to authenticate");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
console.log("🔐 ZK-Proof signup - Gun user created/authenticated");
|
|
224
|
+
}
|
|
225
|
+
catch (createError) {
|
|
226
|
+
throw createError;
|
|
227
|
+
}
|
|
228
|
+
// Set authentication method
|
|
229
|
+
core.setAuthMethod("zkproof");
|
|
230
|
+
// Add to default group
|
|
231
|
+
this.addToGroup(identityData.commitment);
|
|
232
|
+
const result = {
|
|
233
|
+
success: true,
|
|
234
|
+
userPub: gunPair.pub,
|
|
235
|
+
username: username,
|
|
236
|
+
authMethod: "zkproof",
|
|
237
|
+
isNewUser: true,
|
|
238
|
+
// CRITICAL: Include trapdoor for user backup (like seed phrase in WebAuthn)
|
|
239
|
+
seedPhrase: identityData.trapdoor,
|
|
240
|
+
sea: {
|
|
241
|
+
pub: gunPair.pub,
|
|
242
|
+
priv: gunPair.priv,
|
|
243
|
+
epub: gunPair.epub,
|
|
244
|
+
epriv: gunPair.epriv,
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
// Emit signup event
|
|
248
|
+
core.emit("auth:signup", {
|
|
249
|
+
userPub: gunPair.pub,
|
|
250
|
+
username: username,
|
|
251
|
+
method: "zkproof",
|
|
252
|
+
});
|
|
253
|
+
console.log("🔐 ZK-Proof signup - complete");
|
|
254
|
+
console.log(`⚠️ IMPORTANT: Save the trapdoor (seed phrase) for account recovery!`);
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
|
|
259
|
+
const errorCode = error?.code || "ZK_SIGNUP_ERROR";
|
|
260
|
+
const errorMessage = error?.message || "Unknown error during ZK-Proof signup";
|
|
261
|
+
errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
|
|
262
|
+
return { success: false, error: errorMessage };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Check if ZK-Proof is available
|
|
267
|
+
*/
|
|
268
|
+
isAvailable() {
|
|
269
|
+
return typeof window !== "undefined" || typeof global !== "undefined";
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.ZkProofPlugin = ZkProofPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZK-Proof Verifiable Credentials Example
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates how to use ZK-Proof for proving attributes
|
|
5
|
+
* about documents and identity without revealing sensitive data
|
|
6
|
+
*/
|
|
7
|
+
declare function ageVerificationExample(): Promise<void>;
|
|
8
|
+
declare function citizenshipExample(): Promise<void>;
|
|
9
|
+
declare function educationExample(): Promise<void>;
|
|
10
|
+
declare function incomeExample(): Promise<void>;
|
|
11
|
+
declare function customCredentialExample(): Promise<void>;
|
|
12
|
+
export { ageVerificationExample, citizenshipExample, educationExample, incomeExample, customCredentialExample, };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Knowledge Proof Authentication Example
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the ZK-Proof plugin with Shogun Core
|
|
5
|
+
* for privacy-preserving authentication using Semaphore protocol.
|
|
6
|
+
*/
|
|
7
|
+
declare function basicExample(): Promise<void>;
|
|
8
|
+
declare function deterministicExample(): Promise<void>;
|
|
9
|
+
declare function proofExample(): Promise<void>;
|
|
10
|
+
declare function multiDeviceExample(): Promise<void>;
|
|
11
|
+
export { basicExample, deterministicExample, proofExample, multiDeviceExample };
|
|
@@ -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
|
+
}
|