shogun-core 6.2.3 → 6.3.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/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
- package/dist/browser/shogun-core.js +138850 -146638
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{core.js → src/core.js} +167 -107
- package/dist/src/crypto/asymmetric.js +168 -0
- package/dist/src/crypto/double-ratchet.js +908 -0
- package/dist/src/crypto/file-encryption.js +352 -0
- package/dist/src/crypto/hashing.js +160 -0
- package/dist/src/crypto/index.js +18 -0
- package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
- package/dist/src/crypto/mls.js +734 -0
- package/dist/src/crypto/pgp.js +619 -0
- package/dist/{crypto → src/crypto}/random-generation.js +125 -103
- package/dist/src/crypto/sframe.js +466 -0
- package/dist/src/crypto/signal-protocol.js +943 -0
- package/dist/src/crypto/symmetric.js +165 -0
- package/dist/src/crypto/utils.js +220 -0
- package/dist/src/examples/auth-test.js +535 -0
- package/dist/src/examples/crypto-identity-example.js +294 -0
- package/dist/src/examples/crypto-working-test.js +149 -0
- package/dist/src/examples/double-ratchet-test.js +240 -0
- package/dist/src/examples/mls-3-member-test.js +183 -0
- package/dist/src/examples/mls-multi-member.js +439 -0
- package/dist/src/examples/mls-sframe-test.js +491 -0
- package/dist/src/examples/mls-simple-test.js +122 -0
- package/dist/src/examples/pgp-example.js +354 -0
- package/dist/src/examples/random-generation-test.js +191 -0
- package/dist/src/examples/shogun-core-example.js +204 -0
- package/dist/src/examples/signal-protocol-test.js +82 -0
- package/dist/src/examples/zkproof-credentials-example.js +357 -0
- package/dist/src/examples/zkproof-example.js +357 -0
- package/dist/src/gundb/crypto.js +420 -0
- package/dist/src/gundb/db.js +728 -0
- package/dist/src/gundb/derive.js +327 -0
- package/dist/src/gundb/errors.js +115 -0
- package/dist/src/gundb/gun-es.js +8 -0
- package/dist/src/gundb/index.js +5 -0
- package/dist/{gundb → src/gundb}/rxjs.js +147 -111
- package/dist/{gundb → src/gundb}/types.js +1 -2
- package/dist/src/index.js +19 -0
- package/dist/src/interfaces/events.js +57 -0
- package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
- package/dist/src/managers/AuthManager.js +301 -0
- package/dist/src/managers/CoreInitializer.js +304 -0
- package/dist/src/managers/CryptoIdentityManager.js +230 -0
- package/dist/{managers → src/managers}/EventManager.js +19 -21
- package/dist/{managers → src/managers}/PluginManager.js +123 -89
- package/dist/src/plugins/base.js +90 -0
- package/dist/src/plugins/index.js +17 -0
- package/dist/src/plugins/nostr/index.js +4 -0
- package/dist/src/plugins/nostr/nostrConnector.js +539 -0
- package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
- package/dist/src/plugins/nostr/nostrSigner.js +414 -0
- package/dist/src/plugins/smartwallet/index.js +2 -0
- package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
- package/dist/src/plugins/web3/index.js +4 -0
- package/dist/src/plugins/web3/types.js +1 -0
- package/dist/src/plugins/web3/web3Connector.js +738 -0
- package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
- package/dist/src/plugins/web3/web3Signer.js +432 -0
- package/dist/src/plugins/webauthn/index.js +3 -0
- package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
- package/dist/src/plugins/webauthn/webauthn.js +647 -0
- package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
- package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
- package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
- package/dist/src/plugins/zkproof/types.js +1 -0
- package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
- package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
- package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
- package/dist/src/storage/storage.js +189 -0
- package/dist/src/utils/errorHandler.js +339 -0
- package/dist/{utils → src/utils}/eventEmitter.js +26 -26
- package/dist/{utils → src/utils}/seedPhrase.js +23 -32
- package/dist/{utils → src/utils}/validation.js +14 -21
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
- package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
- package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
- package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/src/examples/random-generation-test.d.ts +1 -0
- package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
- package/dist/types/src/gundb/gun-es.d.ts +8 -0
- package/dist/types/src/gundb/min.d.ts +3 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
- package/package.json +14 -11
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
- package/dist/crypto/asymmetric.js +0 -99
- package/dist/crypto/double-ratchet.js +0 -370
- package/dist/crypto/file-encryption.js +0 -213
- package/dist/crypto/hashing.js +0 -87
- package/dist/crypto/index.js +0 -34
- package/dist/crypto/mls.js +0 -569
- package/dist/crypto/pgp.js +0 -390
- package/dist/crypto/sframe.js +0 -352
- package/dist/crypto/signal-protocol.js +0 -456
- package/dist/crypto/symmetric.js +0 -91
- package/dist/crypto/types.js +0 -2
- package/dist/crypto/utils.js +0 -140
- package/dist/examples/auth-test.js +0 -453
- package/dist/examples/crypto-identity-example.js +0 -196
- package/dist/examples/crypto-working-test.js +0 -83
- package/dist/examples/double-ratchet-test.js +0 -155
- package/dist/examples/mls-3-member-test.js +0 -97
- package/dist/examples/mls-multi-member.js +0 -153
- package/dist/examples/mls-sframe-test.js +0 -307
- package/dist/examples/mls-simple-test.js +0 -58
- package/dist/examples/pgp-example.js +0 -200
- package/dist/examples/random-generation-test.js +0 -151
- package/dist/examples/shogun-core-example.js +0 -150
- package/dist/examples/signal-protocol-test.js +0 -38
- package/dist/examples/zkproof-credentials-example.js +0 -217
- package/dist/examples/zkproof-example.js +0 -242
- package/dist/gundb/crypto.js +0 -306
- package/dist/gundb/db.js +0 -485
- package/dist/gundb/derive.js +0 -232
- package/dist/gundb/errors.js +0 -76
- package/dist/gundb/gun-es.js +0 -12
- package/dist/gundb/index.js +0 -21
- package/dist/gundb/min.js +0 -10
- package/dist/index.esm.js +0 -22
- package/dist/index.js +0 -47
- package/dist/interfaces/common.js +0 -2
- package/dist/interfaces/events.js +0 -40
- package/dist/interfaces/plugin.js +0 -2
- package/dist/managers/AuthManager.js +0 -226
- package/dist/managers/CoreInitializer.js +0 -250
- package/dist/managers/CryptoIdentityManager.js +0 -138
- package/dist/plugins/base.js +0 -50
- package/dist/plugins/index.js +0 -32
- package/dist/plugins/nostr/index.js +0 -20
- package/dist/plugins/nostr/nostrConnector.js +0 -419
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
- package/dist/plugins/nostr/nostrSigner.js +0 -319
- package/dist/plugins/nostr/types.js +0 -2
- package/dist/plugins/smartwallet/index.js +0 -18
- package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
- package/dist/plugins/smartwallet/types.js +0 -2
- package/dist/plugins/web3/index.js +0 -20
- package/dist/plugins/web3/types.js +0 -2
- package/dist/plugins/web3/web3Connector.js +0 -533
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
- package/dist/plugins/web3/web3Signer.js +0 -314
- package/dist/plugins/webauthn/index.js +0 -19
- package/dist/plugins/webauthn/webauthn.js +0 -496
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
- package/dist/plugins/webauthn/webauthnSigner.js +0 -310
- package/dist/plugins/zkproof/types.js +0 -2
- package/dist/plugins/zkproof/zkCredentials.js +0 -216
- package/dist/plugins/zkproof/zkProofConnector.js +0 -198
- package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
- package/dist/storage/storage.js +0 -145
- package/dist/types/gundb/gun-es.d.ts +0 -8
- package/dist/utils/errorHandler.js +0 -246
- /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
- /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
- /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
- /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
- /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
- /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
- /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
- /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
- /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// MLS and SFrame test - Updated for RFC-compliant implementations
|
|
4
|
-
const crypto_1 = require("../crypto");
|
|
5
|
-
// Test MLS (Message Layer Security) - RFC 9420
|
|
6
|
-
async function testMLS() {
|
|
7
|
-
try {
|
|
8
|
-
console.log("🔐 Starting MLS RFC 9420 test...");
|
|
9
|
-
// Create MLS managers for Alice, Bob, and Charlie
|
|
10
|
-
const aliceManager = new crypto_1.MLSManager("alice");
|
|
11
|
-
const bobManager = new crypto_1.MLSManager("bob");
|
|
12
|
-
const charlieManager = new crypto_1.MLSManager("charlie");
|
|
13
|
-
// Initialize all managers
|
|
14
|
-
await aliceManager.initialize();
|
|
15
|
-
await bobManager.initialize();
|
|
16
|
-
await charlieManager.initialize();
|
|
17
|
-
console.log("✅ MLS managers initialized");
|
|
18
|
-
// Alice creates a group
|
|
19
|
-
const groupInfo = await aliceManager.createGroup("test-group");
|
|
20
|
-
console.log("✅ Group created:", groupInfo);
|
|
21
|
-
// Export key packages
|
|
22
|
-
const aliceKeyPackage = aliceManager.getKeyPackage();
|
|
23
|
-
const bobKeyPackage = bobManager.getKeyPackage();
|
|
24
|
-
const charlieKeyPackage = charlieManager.getKeyPackage();
|
|
25
|
-
if (!aliceKeyPackage || !bobKeyPackage || !charlieKeyPackage) {
|
|
26
|
-
throw new Error("Failed to get key packages");
|
|
27
|
-
}
|
|
28
|
-
console.log("✅ Key packages exported");
|
|
29
|
-
// Alice adds Bob and Charlie to the group
|
|
30
|
-
const addResult = await aliceManager.addMembers("test-group", [
|
|
31
|
-
bobKeyPackage,
|
|
32
|
-
charlieKeyPackage,
|
|
33
|
-
]);
|
|
34
|
-
console.log("✅ Members added to group");
|
|
35
|
-
// Send welcome to Bob
|
|
36
|
-
const bobWelcome = await bobManager.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
37
|
-
console.log("✅ Bob joined group:", bobWelcome);
|
|
38
|
-
// Send welcome to Charlie
|
|
39
|
-
const charlieWelcome = await charlieManager.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
40
|
-
console.log("✅ Charlie joined group:", charlieWelcome);
|
|
41
|
-
// Alice processes the commit to update her state
|
|
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
|
-
// Test messaging
|
|
45
|
-
const message1 = await aliceManager.encryptMessage("test-group", "Hello MLS group!");
|
|
46
|
-
console.log("✅ Message encrypted");
|
|
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
|
-
// Test key rotation
|
|
50
|
-
const updateCommit = await aliceManager.updateKey("test-group");
|
|
51
|
-
console.log("✅ Key rotation performed");
|
|
52
|
-
// Process update commit for all members
|
|
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)");
|
|
55
|
-
await bobManager.processCommit("test-group", updateCommit);
|
|
56
|
-
await charlieManager.processCommit("test-group", updateCommit);
|
|
57
|
-
console.log("✅ All members processed key rotation");
|
|
58
|
-
const result = {
|
|
59
|
-
success: true,
|
|
60
|
-
groupInfo: await aliceManager.getGroupKeyInfo("test-group"),
|
|
61
|
-
messagesExchanged: 1,
|
|
62
|
-
memberCount: 3,
|
|
63
|
-
currentEpoch: groupInfo.epoch.toString(),
|
|
64
|
-
demonstration: {
|
|
65
|
-
groupMessaging: true,
|
|
66
|
-
forwardSecrecy: true,
|
|
67
|
-
memberManagement: true,
|
|
68
|
-
epochUpdates: true,
|
|
69
|
-
rfc9420Compliant: true,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
console.log("✅ MLS RFC 9420 test completed successfully");
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error("❌ MLS test error:", error);
|
|
77
|
-
return {
|
|
78
|
-
success: false,
|
|
79
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
// Test SFrame (Secure Frame) - RFC 9605
|
|
84
|
-
async function testSFrame() {
|
|
85
|
-
try {
|
|
86
|
-
console.log("🎥 Starting SFrame RFC 9605 test...");
|
|
87
|
-
// Create SFrame managers for Alice (sender) and Bob (receiver)
|
|
88
|
-
const aliceManager = new crypto_1.SFrameManager();
|
|
89
|
-
const bobManager = new crypto_1.SFrameManager();
|
|
90
|
-
await aliceManager.initialize();
|
|
91
|
-
await bobManager.initialize();
|
|
92
|
-
console.log("✅ SFrame managers initialized");
|
|
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);
|
|
99
|
-
bobManager.setActiveKey(0);
|
|
100
|
-
// Simulate media frames
|
|
101
|
-
const testFrames = [
|
|
102
|
-
new TextEncoder().encode("Video Frame 1: Hello World!"),
|
|
103
|
-
new TextEncoder().encode("Video Frame 2: This is encrypted!"),
|
|
104
|
-
new TextEncoder().encode("Video Frame 3: SFrame is working!"),
|
|
105
|
-
new TextEncoder().encode("Audio Frame 1: Sound data"),
|
|
106
|
-
new TextEncoder().encode("Audio Frame 2: More sound data"),
|
|
107
|
-
];
|
|
108
|
-
const encryptedFrames = [];
|
|
109
|
-
const decryptedFrames = [];
|
|
110
|
-
// Encrypt frames with Alice
|
|
111
|
-
console.log("🔒 Encrypting frames...");
|
|
112
|
-
for (const frame of testFrames) {
|
|
113
|
-
const encryptedFrame = await aliceManager.encryptFrame(frame.buffer);
|
|
114
|
-
encryptedFrames.push(encryptedFrame);
|
|
115
|
-
}
|
|
116
|
-
// Decrypt frames with Bob
|
|
117
|
-
console.log("🔓 Decrypting frames...");
|
|
118
|
-
for (const encryptedFrame of encryptedFrames) {
|
|
119
|
-
const decryptedFrame = await bobManager.decryptFrame(encryptedFrame);
|
|
120
|
-
decryptedFrames.push(decryptedFrame);
|
|
121
|
-
}
|
|
122
|
-
// Verify decryption
|
|
123
|
-
let allFramesMatch = true;
|
|
124
|
-
for (let i = 0; i < testFrames.length; i++) {
|
|
125
|
-
const original = new TextDecoder().decode(testFrames[i]);
|
|
126
|
-
const decrypted = new TextDecoder().decode(decryptedFrames[i]);
|
|
127
|
-
if (original !== decrypted) {
|
|
128
|
-
allFramesMatch = false;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Test key rotation
|
|
133
|
-
const newKeyId = await aliceManager.rotateKey();
|
|
134
|
-
console.log("✅ Key rotated to:", newKeyId);
|
|
135
|
-
// Get statistics
|
|
136
|
-
const aliceStats = aliceManager.getStats();
|
|
137
|
-
const bobStats = bobManager.getStats();
|
|
138
|
-
const result = {
|
|
139
|
-
success: true,
|
|
140
|
-
framesProcessed: testFrames.length,
|
|
141
|
-
allFramesMatch,
|
|
142
|
-
aliceStats,
|
|
143
|
-
bobStats,
|
|
144
|
-
demonstration: {
|
|
145
|
-
mediaEncryption: true,
|
|
146
|
-
lowOverhead: true,
|
|
147
|
-
realTimeCapable: true,
|
|
148
|
-
keyRotation: true,
|
|
149
|
-
statistics: true,
|
|
150
|
-
rfc9605Compliant: true,
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
console.log("✅ SFrame RFC 9605 test completed successfully");
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
console.error("❌ SFrame test error:", error);
|
|
158
|
-
return {
|
|
159
|
-
success: false,
|
|
160
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
// Test MLS-SFrame integration
|
|
165
|
-
async function testMLSSFrameIntegration() {
|
|
166
|
-
try {
|
|
167
|
-
console.log("🔗 Starting MLS-SFrame integration test...");
|
|
168
|
-
// Create MLS group
|
|
169
|
-
const aliceMLS = new crypto_1.MLSManager("alice");
|
|
170
|
-
const bobMLS = new crypto_1.MLSManager("bob");
|
|
171
|
-
await aliceMLS.initialize();
|
|
172
|
-
await bobMLS.initialize();
|
|
173
|
-
const groupInfo = await aliceMLS.createGroup("media-group");
|
|
174
|
-
const bobKeyPackage = bobMLS.getKeyPackage();
|
|
175
|
-
if (!bobKeyPackage) {
|
|
176
|
-
throw new Error("Failed to get Bob's key package");
|
|
177
|
-
}
|
|
178
|
-
const addResult = await aliceMLS.addMembers("media-group", [bobKeyPackage]);
|
|
179
|
-
await bobMLS.processWelcome(addResult.welcome, addResult.ratchetTree);
|
|
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)");
|
|
182
|
-
console.log("✅ MLS group established");
|
|
183
|
-
// Create SFrame managers
|
|
184
|
-
const aliceSFrame = new crypto_1.SFrameManager();
|
|
185
|
-
const bobSFrame = new crypto_1.SFrameManager();
|
|
186
|
-
await aliceSFrame.initialize();
|
|
187
|
-
await bobSFrame.initialize();
|
|
188
|
-
// Derive SFrame keys from MLS group secret
|
|
189
|
-
// Note: In real implementation, you'd get the actual MLS group secret
|
|
190
|
-
const mockMLSSecret = new TextEncoder().encode("mls-group-secret").buffer;
|
|
191
|
-
await aliceSFrame.deriveKeyFromMLSSecret(mockMLSSecret, 0);
|
|
192
|
-
await bobSFrame.deriveKeyFromMLSSecret(mockMLSSecret, 0);
|
|
193
|
-
console.log("✅ SFrame keys derived from MLS");
|
|
194
|
-
// Test media encryption with MLS-derived keys
|
|
195
|
-
const mediaFrame = new TextEncoder().encode("Secure media frame from MLS group");
|
|
196
|
-
const encryptedFrame = await aliceSFrame.encryptFrame(mediaFrame.buffer);
|
|
197
|
-
const decryptedFrame = await bobSFrame.decryptFrame(encryptedFrame);
|
|
198
|
-
const dataMatches = new TextDecoder().decode(mediaFrame) ===
|
|
199
|
-
new TextDecoder().decode(decryptedFrame);
|
|
200
|
-
const result = {
|
|
201
|
-
success: true,
|
|
202
|
-
mlsGroupEstablished: true,
|
|
203
|
-
sframeKeysDerived: true,
|
|
204
|
-
mediaEncryptionWorking: dataMatches,
|
|
205
|
-
integration: {
|
|
206
|
-
mlsGroupMessaging: true,
|
|
207
|
-
sframeMediaEncryption: true,
|
|
208
|
-
keyDerivationFromMLS: true,
|
|
209
|
-
endToEndSecurity: true,
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
console.log("✅ MLS-SFrame integration test completed successfully");
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
console.error("❌ MLS-SFrame integration test error:", error);
|
|
217
|
-
return {
|
|
218
|
-
success: false,
|
|
219
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
// Test codec functionality
|
|
224
|
-
async function testCodec() {
|
|
225
|
-
try {
|
|
226
|
-
console.log("📦 Starting MLS codec test...");
|
|
227
|
-
// Create a manager and get key package
|
|
228
|
-
const manager = new crypto_1.MLSManager("test-user");
|
|
229
|
-
await manager.initialize();
|
|
230
|
-
const keyPackage = manager.getKeyPackage();
|
|
231
|
-
if (!keyPackage) {
|
|
232
|
-
throw new Error("Failed to get key package");
|
|
233
|
-
}
|
|
234
|
-
// Test encoding/decoding
|
|
235
|
-
const encoded = (0, crypto_1.encodeKeyPackage)(keyPackage.publicPackage);
|
|
236
|
-
const decoded = (0, crypto_1.decodeKeyPackage)(encoded);
|
|
237
|
-
console.log("✅ Key package encoding/decoding successful");
|
|
238
|
-
// Test group creation and encoding
|
|
239
|
-
const groupInfo = await manager.createGroup("codec-test");
|
|
240
|
-
const encodedGroup = (0, crypto_1.encodeRatchetTree)([]);
|
|
241
|
-
const decodedGroup = (0, crypto_1.decodeRatchetTree)(encodedGroup);
|
|
242
|
-
console.log("✅ Ratchet tree encoding/decoding successful");
|
|
243
|
-
const result = {
|
|
244
|
-
success: true,
|
|
245
|
-
keyPackageCodec: true,
|
|
246
|
-
ratchetTreeCodec: true,
|
|
247
|
-
serialization: true,
|
|
248
|
-
};
|
|
249
|
-
console.log("✅ MLS codec test completed successfully");
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
console.error("❌ Codec test error:", error);
|
|
254
|
-
return {
|
|
255
|
-
success: false,
|
|
256
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// Run all tests
|
|
261
|
-
async function runAllTests() {
|
|
262
|
-
console.log("🚀 Running all MLS and SFrame RFC-compliant tests...\n");
|
|
263
|
-
// Test 1: MLS RFC 9420 demonstration
|
|
264
|
-
console.log("=== Test 1: MLS RFC 9420 Demonstration ===");
|
|
265
|
-
const mlsResult = await testMLS();
|
|
266
|
-
console.log("\n=== Test 2: SFrame RFC 9605 Demonstration ===");
|
|
267
|
-
const sframeResult = await testSFrame();
|
|
268
|
-
console.log("\n=== Test 3: MLS-SFrame Integration ===");
|
|
269
|
-
const integrationResult = await testMLSSFrameIntegration();
|
|
270
|
-
console.log("\n=== Test 4: MLS Codec Testing ===");
|
|
271
|
-
const codecResult = await testCodec();
|
|
272
|
-
console.log("\n📊 Final Results:");
|
|
273
|
-
console.log("MLS RFC 9420:", mlsResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
274
|
-
console.log("SFrame RFC 9605:", sframeResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
275
|
-
console.log("MLS-SFrame Integration:", integrationResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
276
|
-
console.log("MLS Codec:", codecResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
277
|
-
const allPassed = mlsResult.success &&
|
|
278
|
-
sframeResult.success &&
|
|
279
|
-
integrationResult.success &&
|
|
280
|
-
codecResult.success;
|
|
281
|
-
if (allPassed) {
|
|
282
|
-
console.log("\n🎉 All MLS and SFrame RFC-compliant tests completed successfully!");
|
|
283
|
-
console.log("🔒 RFC 9420 MLS: End-to-end encrypted group messaging with forward secrecy");
|
|
284
|
-
console.log("🎥 RFC 9605 SFrame: Real-time media encryption with low overhead");
|
|
285
|
-
console.log("🔗 Integration: MLS-derived keys for SFrame media encryption");
|
|
286
|
-
console.log("📦 Codec: Serialization support for MLS messages");
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
console.log("\n❌ Some tests failed");
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
mls: mlsResult,
|
|
293
|
-
sframe: sframeResult,
|
|
294
|
-
integration: integrationResult,
|
|
295
|
-
codec: codecResult,
|
|
296
|
-
allPassed,
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
// Run the tests
|
|
300
|
-
runAllTests()
|
|
301
|
-
.then((result) => {
|
|
302
|
-
console.log("\n📊 Final Test Summary:");
|
|
303
|
-
console.log(JSON.stringify(result, (key, value) => (typeof value === "bigint" ? value.toString() : value), 2));
|
|
304
|
-
})
|
|
305
|
-
.catch((error) => {
|
|
306
|
-
console.error("💥 Test execution failed:", error);
|
|
307
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|