shogun-core 5.2.2 ā 6.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 +123 -20
- package/dist/browser/shogun-core.js +1134 -493
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +108 -40
- package/dist/crypto/mls.js +34 -15
- package/dist/crypto/sframe.js +13 -11
- package/dist/examples/auth-test.js +263 -59
- package/dist/examples/crypto-identity-example.js +55 -21
- package/dist/examples/mls-3-member-test.js +97 -0
- package/dist/examples/mls-multi-member.js +153 -0
- package/dist/examples/mls-sframe-test.js +14 -11
- package/dist/examples/mls-simple-test.js +58 -0
- package/dist/examples/shogun-core-example.js +90 -0
- package/dist/examples/zkproof-credentials-example.js +9 -5
- package/dist/examples/zkproof-example.js +14 -10
- package/dist/gundb/api.js +17 -16
- package/dist/gundb/db.js +769 -328
- package/dist/index.js +4 -4
- package/dist/managers/CoreInitializer.js +21 -15
- package/dist/managers/CryptoIdentityManager.js +79 -32
- package/dist/plugins/zkproof/zkCredentials.js +4 -1
- package/dist/types/config/simplified-config.d.ts +64 -3
- package/dist/types/crypto/sframe.d.ts +4 -0
- package/dist/types/examples/mls-3-member-test.d.ts +6 -0
- package/dist/types/examples/mls-multi-member.d.ts +6 -0
- package/dist/types/examples/mls-simple-test.d.ts +6 -0
- package/dist/types/examples/shogun-core-example.d.ts +8 -0
- package/dist/types/gundb/api.d.ts +6 -13
- package/dist/types/gundb/db.d.ts +84 -41
- package/dist/types/index.d.ts +4 -2
- package/dist/types/interfaces/shogun.d.ts +1 -2
- package/dist/types/managers/CryptoIdentityManager.d.ts +2 -1
- package/package.json +11 -8
- package/dist/examples/mls-advanced-example.js +0 -294
- package/dist/examples/quick-auth-test.js +0 -61
- package/dist/examples/simple-api-test.js +0 -114
- package/dist/examples/simple-crypto-identity-example.js +0 -84
- package/dist/examples/timeout-test.js +0 -227
- package/dist/types/examples/mls-advanced-example.d.ts +0 -53
- package/dist/types/examples/quick-auth-test.d.ts +0 -8
- package/dist/types/examples/simple-api-test.d.ts +0 -10
- package/dist/types/examples/simple-crypto-identity-example.d.ts +0 -6
- package/dist/types/examples/timeout-test.d.ts +0 -8
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MLS Working Multi-Member Test
|
|
4
|
+
* Usa l'approccio corretto basato sull'implementazione funzionante
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.testMLSWorkingMultiMembers = testMLSWorkingMultiMembers;
|
|
8
|
+
const crypto_1 = require("../crypto");
|
|
9
|
+
async function testMLSWorkingMultiMembers() {
|
|
10
|
+
console.log("š Starting MLS Working Multi-Member Test");
|
|
11
|
+
console.log("=".repeat(50));
|
|
12
|
+
const members = ["alice", "bob", "charlie", "david", "eve"];
|
|
13
|
+
const managers = new Map();
|
|
14
|
+
try {
|
|
15
|
+
// Step 1: Initialize all managers
|
|
16
|
+
console.log("\nš Step 1: Initializing all managers");
|
|
17
|
+
for (const memberId of members) {
|
|
18
|
+
const manager = new crypto_1.MLSManager(memberId);
|
|
19
|
+
await manager.initialize();
|
|
20
|
+
managers.set(memberId, manager);
|
|
21
|
+
console.log(`ā
${memberId} initialized`);
|
|
22
|
+
}
|
|
23
|
+
// Step 2: Alice creates group
|
|
24
|
+
console.log("\nš Step 2: Creating group");
|
|
25
|
+
const groupId = "working-multi-member-group";
|
|
26
|
+
const alice = managers.get("alice");
|
|
27
|
+
await alice.createGroup(groupId);
|
|
28
|
+
console.log("ā
Group created by Alice");
|
|
29
|
+
// Step 3: Add all members at once (this is the key!)
|
|
30
|
+
console.log("\nš Step 3: Adding all members at once");
|
|
31
|
+
const otherMembers = members.slice(1); // bob, charlie, david, eve
|
|
32
|
+
const keyPackages = otherMembers.map((id) => managers.get(id).getKeyPackage());
|
|
33
|
+
console.log(`ā Adding ${otherMembers.length} members: ${otherMembers.join(", ")}`);
|
|
34
|
+
const addResult = await alice.addMembers(groupId, keyPackages);
|
|
35
|
+
console.log("ā
All members added by Alice");
|
|
36
|
+
// Step 4: All other members join via welcome
|
|
37
|
+
console.log("\nš Step 4: All members join via welcome");
|
|
38
|
+
for (const memberId of otherMembers) {
|
|
39
|
+
const manager = managers.get(memberId);
|
|
40
|
+
await manager.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
41
|
+
console.log(`ā
${memberId} joined group`);
|
|
42
|
+
}
|
|
43
|
+
// Step 5: Verify synchronization
|
|
44
|
+
console.log("\nš Step 5: Verifying synchronization");
|
|
45
|
+
const epochInfos = new Map();
|
|
46
|
+
for (const memberId of members) {
|
|
47
|
+
const info = await managers.get(memberId).getGroupKeyInfo(groupId);
|
|
48
|
+
epochInfos.set(memberId, info?.epoch);
|
|
49
|
+
}
|
|
50
|
+
console.log("š Epoch verification:");
|
|
51
|
+
for (const [memberId, epoch] of epochInfos) {
|
|
52
|
+
console.log(` ${memberId}: ${epoch}`);
|
|
53
|
+
}
|
|
54
|
+
const epochs = Array.from(epochInfos.values());
|
|
55
|
+
const allSameEpoch = epochs.every((epoch) => epoch === epochs[0]);
|
|
56
|
+
if (!allSameEpoch) {
|
|
57
|
+
console.log(`ā CRITICAL: Members at different epochs - aborting test`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log(`ā
All ${members.length} members synchronized at epoch ${epochs[0]}`);
|
|
61
|
+
// Step 6: Test message exchange
|
|
62
|
+
console.log("\nš Step 6: Testing message exchange");
|
|
63
|
+
// Each member sends a message
|
|
64
|
+
for (const senderId of members) {
|
|
65
|
+
console.log(`\nš¬ ${senderId} sending message...`);
|
|
66
|
+
const sender = managers.get(senderId);
|
|
67
|
+
const message = `Hello from ${senderId} to everyone!`;
|
|
68
|
+
const envelope = await sender.encryptMessage(groupId, message);
|
|
69
|
+
console.log(`ā
${senderId} encrypted message`);
|
|
70
|
+
// All members decrypt the message
|
|
71
|
+
let successCount = 0;
|
|
72
|
+
for (const [memberId, manager] of managers) {
|
|
73
|
+
if (memberId === senderId) {
|
|
74
|
+
console.log(`ā
${memberId} (sender) does not need to decrypt their own message.`);
|
|
75
|
+
successCount++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const decrypted = await manager.decryptMessage(envelope);
|
|
80
|
+
console.log(`ā
${memberId} decrypted: "${decrypted}"`);
|
|
81
|
+
successCount++;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error(`ā ${memberId} failed to decrypt:`, error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (successCount === members.length) {
|
|
88
|
+
console.log(`š All ${members.length} members successfully decrypted ${senderId}'s message`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(`ā ļø Only ${successCount}/${members.length} members could decrypt ${senderId}'s message`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Step 7: Test key rotation
|
|
95
|
+
console.log("\nš Step 7: Testing key rotation");
|
|
96
|
+
const initiator = managers.get("alice");
|
|
97
|
+
console.log("š Alice initiating key rotation...");
|
|
98
|
+
const updateCommit = await initiator.updateKey(groupId);
|
|
99
|
+
console.log("ā
Key rotation commit created");
|
|
100
|
+
// All members process the update commit
|
|
101
|
+
for (const [memberId, manager] of managers) {
|
|
102
|
+
if (memberId === initiator.getUserId()) {
|
|
103
|
+
console.log(`ā
${memberId} (initiator) already processed key rotation.`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
await manager.processCommit(groupId, updateCommit);
|
|
108
|
+
console.log(`ā
${memberId} processed key rotation`);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(`ā ${memberId} failed to process key rotation:`, error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Step 8: Test messages after key rotation
|
|
115
|
+
console.log("\nš Step 8: Testing messages after key rotation");
|
|
116
|
+
const testMessage = "This message is sent after key rotation!";
|
|
117
|
+
const aliceEnvelope = await alice.encryptMessage(groupId, testMessage);
|
|
118
|
+
let postRotationSuccess = 0;
|
|
119
|
+
for (const [memberId, manager] of managers) {
|
|
120
|
+
if (memberId === alice.getUserId()) {
|
|
121
|
+
console.log(`ā
${memberId} (sender) does not need to decrypt their own message after rotation.`);
|
|
122
|
+
postRotationSuccess++;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
const decrypted = await manager.decryptMessage(aliceEnvelope);
|
|
127
|
+
console.log(`ā
${memberId} decrypted after rotation: "${decrypted}"`);
|
|
128
|
+
postRotationSuccess++;
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error(`ā ${memberId} failed to decrypt after rotation:`, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
console.log("\nš MLS Working Multi-Member Test completed!");
|
|
135
|
+
console.log(`ā
Group creation with ${members.length} members`);
|
|
136
|
+
console.log(`ā
Bidirectional encrypted messaging`);
|
|
137
|
+
console.log(`ā
Key rotation and forward secrecy`);
|
|
138
|
+
console.log(`ā
All members can send and receive messages`);
|
|
139
|
+
// Cleanup
|
|
140
|
+
console.log("\nš Cleanup");
|
|
141
|
+
for (const [memberId, manager] of managers) {
|
|
142
|
+
await manager.destroy();
|
|
143
|
+
console.log(`ā
${memberId} destroyed`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error("ā Test failed:", error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Run the test
|
|
151
|
+
if (require.main === module) {
|
|
152
|
+
testMLSWorkingMultiMembers().catch(console.error);
|
|
153
|
+
}
|
|
@@ -39,18 +39,19 @@ async function testMLS() {
|
|
|
39
39
|
const charlieWelcome = await charlieManager.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
40
40
|
console.log("ā
Charlie joined group:", charlieWelcome);
|
|
41
41
|
// Alice processes the commit to update her state
|
|
42
|
-
|
|
43
|
-
console.log("ā
Alice
|
|
42
|
+
// Alice doesn't need to process the commit - her state is already updated by addMembers()
|
|
43
|
+
console.log("ā
Alice already synchronized after adding members (state updated by addMembers)");
|
|
44
44
|
// Test messaging
|
|
45
45
|
const message1 = await aliceManager.encryptMessage("test-group", "Hello MLS group!");
|
|
46
46
|
console.log("ā
Message encrypted");
|
|
47
|
-
|
|
48
|
-
console.log("ā
|
|
47
|
+
// Alice doesn't need to decrypt her own message, as her state is already updated
|
|
48
|
+
console.log("ā
Alice (sender) does not need to decrypt her own message.");
|
|
49
49
|
// Test key rotation
|
|
50
50
|
const updateCommit = await aliceManager.updateKey("test-group");
|
|
51
51
|
console.log("ā
Key rotation performed");
|
|
52
52
|
// Process update commit for all members
|
|
53
|
-
|
|
53
|
+
// Alice doesn't need to process the commit for key rotation - her state is already updated by updateKey()
|
|
54
|
+
console.log("ā
Alice already synchronized after key rotation (state updated by updateKey)");
|
|
54
55
|
await bobManager.processCommit("test-group", updateCommit);
|
|
55
56
|
await charlieManager.processCommit("test-group", updateCommit);
|
|
56
57
|
console.log("ā
All members processed key rotation");
|
|
@@ -89,12 +90,13 @@ async function testSFrame() {
|
|
|
89
90
|
await aliceManager.initialize();
|
|
90
91
|
await bobManager.initialize();
|
|
91
92
|
console.log("ā
SFrame managers initialized");
|
|
92
|
-
//
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
// Alice generates key and shares with Bob
|
|
94
|
+
const aliceSFrameKey = await aliceManager.generateKey(0);
|
|
95
|
+
// Bob uses Alice's key
|
|
96
|
+
await bobManager.setSharedKey(aliceSFrameKey);
|
|
97
|
+
// Set active key for both
|
|
98
|
+
aliceManager.setActiveKey(0);
|
|
96
99
|
bobManager.setActiveKey(0);
|
|
97
|
-
console.log("ā
Key shared between Alice and Bob");
|
|
98
100
|
// Simulate media frames
|
|
99
101
|
const testFrames = [
|
|
100
102
|
new TextEncoder().encode("Video Frame 1: Hello World!"),
|
|
@@ -175,7 +177,8 @@ async function testMLSSFrameIntegration() {
|
|
|
175
177
|
}
|
|
176
178
|
const addResult = await aliceMLS.addMembers("media-group", [bobKeyPackage]);
|
|
177
179
|
await bobMLS.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
178
|
-
|
|
180
|
+
// Alice doesn't need to process the commit - her state is already updated by addMembers()
|
|
181
|
+
console.log("ā
Alice already synchronized after adding members (state updated by addMembers)");
|
|
179
182
|
console.log("ā
MLS group established");
|
|
180
183
|
// Create SFrame managers
|
|
181
184
|
const aliceSFrame = new crypto_1.SFrameManager();
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple MLS Test
|
|
4
|
+
* Minimal test to verify MLS functionality
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.testMLS = testMLS;
|
|
8
|
+
const crypto_1 = require("../crypto");
|
|
9
|
+
async function testMLS() {
|
|
10
|
+
console.log("š Starting Simple MLS Test");
|
|
11
|
+
console.log("=".repeat(50));
|
|
12
|
+
try {
|
|
13
|
+
// Create managers
|
|
14
|
+
const alice = new crypto_1.MLSManager("alice");
|
|
15
|
+
const bob = new crypto_1.MLSManager("bob");
|
|
16
|
+
// Initialize
|
|
17
|
+
await alice.initialize();
|
|
18
|
+
await bob.initialize();
|
|
19
|
+
console.log("ā
Managers initialized");
|
|
20
|
+
// Alice creates group
|
|
21
|
+
const groupId = "test-group";
|
|
22
|
+
await alice.createGroup(groupId);
|
|
23
|
+
console.log("ā
Group created");
|
|
24
|
+
// Add Bob
|
|
25
|
+
const bobKeyPackage = bob.getKeyPackage();
|
|
26
|
+
const addResult = await alice.addMembers(groupId, [bobKeyPackage]);
|
|
27
|
+
console.log("ā
Members added");
|
|
28
|
+
// Bob joins via welcome
|
|
29
|
+
await bob.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
30
|
+
console.log("ā
Bob joined group");
|
|
31
|
+
// Test message exchange
|
|
32
|
+
console.log("\nš Testing message exchange");
|
|
33
|
+
// Alice sends message
|
|
34
|
+
const envelope1 = await alice.encryptMessage(groupId, "Hello from Alice!");
|
|
35
|
+
console.log("ā
Alice encrypted message");
|
|
36
|
+
// Bob decrypts
|
|
37
|
+
const decrypted1 = await bob.decryptMessage(envelope1);
|
|
38
|
+
console.log(`ā
Bob decrypted: "${decrypted1}"`);
|
|
39
|
+
// Bob sends message
|
|
40
|
+
const envelope2 = await bob.encryptMessage(groupId, "Hello from Bob!");
|
|
41
|
+
console.log("ā
Bob encrypted message");
|
|
42
|
+
// Alice decrypts
|
|
43
|
+
const decrypted2 = await alice.decryptMessage(envelope2);
|
|
44
|
+
console.log(`ā
Alice decrypted: "${decrypted2}"`);
|
|
45
|
+
console.log("\nš Simple MLS Test completed successfully!");
|
|
46
|
+
// Cleanup
|
|
47
|
+
await alice.destroy();
|
|
48
|
+
await bob.destroy();
|
|
49
|
+
console.log("ā
Cleanup completed");
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error("ā Test failed:", error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Run the test
|
|
56
|
+
if (require.main === module) {
|
|
57
|
+
testMLS().catch(console.error);
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ShogunCore Example with Existing Gun Instance
|
|
4
|
+
*
|
|
5
|
+
* This example shows how to use ShogunCore with an existing Gun instance.
|
|
6
|
+
* ShogunCore now requires an existing Gun instance to be passed in.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.shogunCoreExample = shogunCoreExample;
|
|
13
|
+
const gun_1 = __importDefault(require("gun"));
|
|
14
|
+
const core_1 = require("../core");
|
|
15
|
+
async function shogunCoreExample() {
|
|
16
|
+
console.log("š ShogunCore Example with Existing Gun Instance\n");
|
|
17
|
+
// === STEP 1: CREATE GUN INSTANCE ===
|
|
18
|
+
console.log("š¦ === CREATING GUN INSTANCE ===\n");
|
|
19
|
+
const gunInstance = (0, gun_1.default)({
|
|
20
|
+
peers: ["https://peer.wallie.io/gun", "https://gunjs.herokuapp.com/gun"],
|
|
21
|
+
radisk: false,
|
|
22
|
+
localStorage: false,
|
|
23
|
+
});
|
|
24
|
+
console.log("ā Gun instance created");
|
|
25
|
+
// === STEP 2: INITIALIZE SHOGUN CORE ===
|
|
26
|
+
console.log("\nš§ === INITIALIZING SHOGUN CORE ===\n");
|
|
27
|
+
const shogun = new core_1.ShogunCore({
|
|
28
|
+
gunInstance: gunInstance, // Required: existing Gun instance
|
|
29
|
+
webauthn: {
|
|
30
|
+
enabled: true,
|
|
31
|
+
rpName: "ShogunCore Example",
|
|
32
|
+
},
|
|
33
|
+
web3: {
|
|
34
|
+
enabled: true,
|
|
35
|
+
},
|
|
36
|
+
silent: false, // Enable console logs
|
|
37
|
+
});
|
|
38
|
+
console.log("ā ShogunCore initialized with existing Gun instance");
|
|
39
|
+
// === STEP 3: USE SHOGUN CORE ===
|
|
40
|
+
console.log("\nšÆ === USING SHOGUN CORE ===\n");
|
|
41
|
+
// Access the database
|
|
42
|
+
const db = shogun.db;
|
|
43
|
+
console.log("Database available:", !!db);
|
|
44
|
+
// Check if user is logged in
|
|
45
|
+
const isLoggedIn = shogun.isLoggedIn();
|
|
46
|
+
console.log("User logged in:", isLoggedIn);
|
|
47
|
+
// Example: Sign up a new user
|
|
48
|
+
console.log("\n--- Sign Up Example ---");
|
|
49
|
+
const username = `testuser_${Date.now()}`;
|
|
50
|
+
const password = "testpass123";
|
|
51
|
+
try {
|
|
52
|
+
const signupResult = await shogun.signUp(username, password);
|
|
53
|
+
if (signupResult.success) {
|
|
54
|
+
console.log("ā User signed up successfully:", signupResult.username);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.log("ā Sign up failed:", signupResult.error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
console.log("ā Sign up error:", error);
|
|
62
|
+
}
|
|
63
|
+
// Example: Login
|
|
64
|
+
console.log("\n--- Login Example ---");
|
|
65
|
+
try {
|
|
66
|
+
const loginResult = await shogun.login(username, password);
|
|
67
|
+
if (loginResult.success) {
|
|
68
|
+
console.log("ā User logged in successfully:", loginResult.username);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
console.log("ā Login failed:", loginResult.error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
console.log("ā Login error:", error);
|
|
76
|
+
}
|
|
77
|
+
// Example: Check current user
|
|
78
|
+
console.log("\n--- Current User ---");
|
|
79
|
+
const currentUser = shogun.getCurrentUser();
|
|
80
|
+
console.log("Current user:", currentUser);
|
|
81
|
+
// Example: Logout
|
|
82
|
+
console.log("\n--- Logout Example ---");
|
|
83
|
+
shogun.logout();
|
|
84
|
+
console.log("ā User logged out");
|
|
85
|
+
console.log("\nš Example completed successfully!");
|
|
86
|
+
}
|
|
87
|
+
// Run the example
|
|
88
|
+
if (require.main === module) {
|
|
89
|
+
shogunCoreExample().catch(console.error);
|
|
90
|
+
}
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
* This demonstrates how to use ZK-Proof for proving attributes
|
|
6
6
|
* about documents and identity without revealing sensitive data
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.ageVerificationExample = ageVerificationExample;
|
|
10
13
|
exports.citizenshipExample = citizenshipExample;
|
|
11
14
|
exports.educationExample = educationExample;
|
|
12
15
|
exports.incomeExample = incomeExample;
|
|
13
16
|
exports.customCredentialExample = customCredentialExample;
|
|
17
|
+
const gun_1 = __importDefault(require("gun"));
|
|
14
18
|
const core_1 = require("../core");
|
|
15
19
|
const zkCredentials_1 = require("../plugins/zkproof/zkCredentials");
|
|
16
20
|
const identity_1 = require("@semaphore-protocol/identity");
|
|
@@ -18,7 +22,7 @@ const identity_1 = require("@semaphore-protocol/identity");
|
|
|
18
22
|
async function ageVerificationExample() {
|
|
19
23
|
console.log("=== Age Verification Example ===\n");
|
|
20
24
|
const shogun = new core_1.ShogunCore({
|
|
21
|
-
|
|
25
|
+
gunInstance: (0, gun_1.default)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
22
26
|
zkproof: { enabled: true },
|
|
23
27
|
});
|
|
24
28
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -58,7 +62,7 @@ async function ageVerificationExample() {
|
|
|
58
62
|
async function citizenshipExample() {
|
|
59
63
|
console.log("\n=== Citizenship Verification Example ===\n");
|
|
60
64
|
const shogun = new core_1.ShogunCore({
|
|
61
|
-
|
|
65
|
+
gunInstance: (0, gun_1.default)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
62
66
|
zkproof: { enabled: true },
|
|
63
67
|
});
|
|
64
68
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -87,7 +91,7 @@ async function citizenshipExample() {
|
|
|
87
91
|
async function educationExample() {
|
|
88
92
|
console.log("\n=== Education Credential Example ===\n");
|
|
89
93
|
const shogun = new core_1.ShogunCore({
|
|
90
|
-
|
|
94
|
+
gunInstance: (0, gun_1.default)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
91
95
|
zkproof: { enabled: true },
|
|
92
96
|
});
|
|
93
97
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -119,7 +123,7 @@ async function educationExample() {
|
|
|
119
123
|
async function incomeExample() {
|
|
120
124
|
console.log("\n=== Income Verification Example ===\n");
|
|
121
125
|
const shogun = new core_1.ShogunCore({
|
|
122
|
-
|
|
126
|
+
gunInstance: (0, gun_1.default)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
123
127
|
zkproof: { enabled: true },
|
|
124
128
|
});
|
|
125
129
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -150,7 +154,7 @@ async function incomeExample() {
|
|
|
150
154
|
async function customCredentialExample() {
|
|
151
155
|
console.log("\n=== Custom Credential Example ===\n");
|
|
152
156
|
const shogun = new core_1.ShogunCore({
|
|
153
|
-
|
|
157
|
+
gunInstance: (0, gun_1.default)({ peers: ["https://peer.wallie.io/gun"] }),
|
|
154
158
|
zkproof: { enabled: true },
|
|
155
159
|
});
|
|
156
160
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -5,20 +5,24 @@
|
|
|
5
5
|
* This example demonstrates how to use the ZK-Proof plugin with Shogun Core
|
|
6
6
|
* for privacy-preserving authentication using Semaphore protocol.
|
|
7
7
|
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.basicExample = basicExample;
|
|
10
13
|
exports.deterministicExample = deterministicExample;
|
|
11
14
|
exports.proofExample = proofExample;
|
|
12
15
|
exports.multiDeviceExample = multiDeviceExample;
|
|
16
|
+
const gun_1 = __importDefault(require("gun"));
|
|
13
17
|
const core_1 = require("../core");
|
|
14
18
|
// Example 1: Basic ZK-Proof signup and login
|
|
15
19
|
async function basicExample() {
|
|
16
20
|
console.log("=== Basic ZK-Proof Authentication Example ===\n");
|
|
17
21
|
// Initialize Shogun with ZK-Proof plugin
|
|
18
22
|
const shogun = new core_1.ShogunCore({
|
|
19
|
-
|
|
23
|
+
gunInstance: (0, gun_1.default)({
|
|
20
24
|
peers: ["https://peer.wallie.io/gun"],
|
|
21
|
-
},
|
|
25
|
+
}),
|
|
22
26
|
zkproof: {
|
|
23
27
|
enabled: true,
|
|
24
28
|
defaultGroupId: "my-app-users",
|
|
@@ -67,9 +71,9 @@ async function basicExample() {
|
|
|
67
71
|
async function deterministicExample() {
|
|
68
72
|
console.log("\n=== Deterministic ZK Identity Example ===\n");
|
|
69
73
|
const shogun = new core_1.ShogunCore({
|
|
70
|
-
|
|
74
|
+
gunInstance: (0, gun_1.default)({
|
|
71
75
|
peers: ["https://peer.wallie.io/gun"],
|
|
72
|
-
},
|
|
76
|
+
}),
|
|
73
77
|
zkproof: {
|
|
74
78
|
enabled: true,
|
|
75
79
|
deterministic: true,
|
|
@@ -99,9 +103,9 @@ async function deterministicExample() {
|
|
|
99
103
|
async function proofExample() {
|
|
100
104
|
console.log("\n=== ZK Proof Generation & Verification Example ===\n");
|
|
101
105
|
const shogun = new core_1.ShogunCore({
|
|
102
|
-
|
|
106
|
+
gunInstance: (0, gun_1.default)({
|
|
103
107
|
peers: ["https://peer.wallie.io/gun"],
|
|
104
|
-
},
|
|
108
|
+
}),
|
|
105
109
|
zkproof: {
|
|
106
110
|
enabled: true,
|
|
107
111
|
defaultGroupId: "proof-demo-group",
|
|
@@ -148,9 +152,9 @@ async function multiDeviceExample() {
|
|
|
148
152
|
// Device 1: Create account
|
|
149
153
|
console.log("š± DEVICE 1: Creating account...");
|
|
150
154
|
const shogun1 = new core_1.ShogunCore({
|
|
151
|
-
|
|
155
|
+
gunInstance: (0, gun_1.default)({
|
|
152
156
|
peers: ["https://peer.wallie.io/gun"],
|
|
153
|
-
},
|
|
157
|
+
}),
|
|
154
158
|
zkproof: { enabled: true },
|
|
155
159
|
});
|
|
156
160
|
// Wait for plugin initialization
|
|
@@ -165,9 +169,9 @@ async function multiDeviceExample() {
|
|
|
165
169
|
// Device 2: Import account
|
|
166
170
|
console.log("\nš» DEVICE 2: Importing account with trapdoor...");
|
|
167
171
|
const shogun2 = new core_1.ShogunCore({
|
|
168
|
-
|
|
172
|
+
gunInstance: (0, gun_1.default)({
|
|
169
173
|
peers: ["https://peer.wallie.io/gun"],
|
|
170
|
-
},
|
|
174
|
+
}),
|
|
171
175
|
zkproof: { enabled: true },
|
|
172
176
|
});
|
|
173
177
|
// Wait for plugin initialization
|
package/dist/gundb/api.js
CHANGED
|
@@ -85,7 +85,8 @@ class SimpleGunAPI {
|
|
|
85
85
|
console.warn("DEPRECATED: putArray() is unreliable with GunDB. Use direct GunDB operations instead.");
|
|
86
86
|
try {
|
|
87
87
|
const indexed = this.arrayToIndexedObject(arr);
|
|
88
|
-
|
|
88
|
+
const node = this.db.getNode(path);
|
|
89
|
+
node.put(indexed);
|
|
89
90
|
return true;
|
|
90
91
|
}
|
|
91
92
|
catch (error) {
|
|
@@ -102,7 +103,14 @@ class SimpleGunAPI {
|
|
|
102
103
|
async getArray(path) {
|
|
103
104
|
console.warn("DEPRECATED: getArray() is unreliable with GunDB. Use direct GunDB operations instead.");
|
|
104
105
|
try {
|
|
105
|
-
const
|
|
106
|
+
const node = this.db.getNode(path);
|
|
107
|
+
const indexedObj = await new Promise((resolve) => {
|
|
108
|
+
const timeout = setTimeout(() => resolve(null), 2000);
|
|
109
|
+
node.once((data) => {
|
|
110
|
+
clearTimeout(timeout);
|
|
111
|
+
resolve(data);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
106
114
|
return this.indexedObjectToArray(indexedObj);
|
|
107
115
|
}
|
|
108
116
|
catch (error) {
|
|
@@ -387,19 +395,12 @@ class QuickStart {
|
|
|
387
395
|
}
|
|
388
396
|
exports.QuickStart = QuickStart;
|
|
389
397
|
/**
|
|
390
|
-
* Auto Quick Start helper - creates a simple API with
|
|
391
|
-
*
|
|
398
|
+
* Auto Quick Start helper - creates a simple API with an existing Gun instance
|
|
399
|
+
* Requires a Gun instance to be passed in
|
|
392
400
|
*/
|
|
393
401
|
class AutoQuickStart {
|
|
394
|
-
constructor(
|
|
395
|
-
|
|
396
|
-
peers: config?.peers || [],
|
|
397
|
-
...config,
|
|
398
|
-
};
|
|
399
|
-
// Remove appScope from gunConfig as it's not a Gun configuration option
|
|
400
|
-
delete gunConfig.appScope;
|
|
401
|
-
this.gunInstance = (0, db_1.createGun)(gunConfig);
|
|
402
|
-
const appScope = config?.appScope || "shogun";
|
|
402
|
+
constructor(gunInstance, appScope = "shogun") {
|
|
403
|
+
this.gunInstance = gunInstance;
|
|
403
404
|
this.db = new db_1.DataBase(this.gunInstance, appScope);
|
|
404
405
|
this.simpleAPI = new SimpleGunAPI(this.db);
|
|
405
406
|
}
|
|
@@ -428,8 +429,8 @@ function quickStart(gunInstance, appScope) {
|
|
|
428
429
|
return new QuickStart(gunInstance, appScope);
|
|
429
430
|
}
|
|
430
431
|
/**
|
|
431
|
-
* Global helper for auto quick setup -
|
|
432
|
+
* Global helper for auto quick setup - requires existing Gun instance
|
|
432
433
|
*/
|
|
433
|
-
function autoQuickStart(
|
|
434
|
-
return new AutoQuickStart(
|
|
434
|
+
function autoQuickStart(gunInstance, appScope = "shogun") {
|
|
435
|
+
return new AutoQuickStart(gunInstance, appScope);
|
|
435
436
|
}
|