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
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __values = (this && this.__values) || function(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
+
if (m) return m.call(o);
|
|
40
|
+
if (o && typeof o.length === "number") return {
|
|
41
|
+
next: function () {
|
|
42
|
+
if (o && i >= o.length) o = void 0;
|
|
43
|
+
return { value: o && o[i++], done: !o };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
+
};
|
|
48
|
+
// MLS and SFrame test - Updated for RFC-compliant implementations
|
|
49
|
+
import { MLSManager, SFrameManager, encodeKeyPackage, decodeKeyPackage, encodeRatchetTree, decodeRatchetTree, } from "../crypto/index.js";
|
|
50
|
+
// Test MLS (Message Layer Security) - RFC 9420
|
|
51
|
+
function testMLS() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
+
var aliceManager, bobManager, charlieManager, groupInfo, aliceKeyPackage, bobKeyPackage, charlieKeyPackage, addResult, bobWelcome, charlieWelcome, message1, updateCommit, result, error_1;
|
|
54
|
+
var _a;
|
|
55
|
+
return __generator(this, function (_b) {
|
|
56
|
+
switch (_b.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
_b.trys.push([0, 13, , 14]);
|
|
59
|
+
console.log("🔐 Starting MLS RFC 9420 test...");
|
|
60
|
+
aliceManager = new MLSManager("alice");
|
|
61
|
+
bobManager = new MLSManager("bob");
|
|
62
|
+
charlieManager = new MLSManager("charlie");
|
|
63
|
+
// Initialize all managers
|
|
64
|
+
return [4 /*yield*/, aliceManager.initialize()];
|
|
65
|
+
case 1:
|
|
66
|
+
// Initialize all managers
|
|
67
|
+
_b.sent();
|
|
68
|
+
return [4 /*yield*/, bobManager.initialize()];
|
|
69
|
+
case 2:
|
|
70
|
+
_b.sent();
|
|
71
|
+
return [4 /*yield*/, charlieManager.initialize()];
|
|
72
|
+
case 3:
|
|
73
|
+
_b.sent();
|
|
74
|
+
console.log("✅ MLS managers initialized");
|
|
75
|
+
return [4 /*yield*/, aliceManager.createGroup("test-group")];
|
|
76
|
+
case 4:
|
|
77
|
+
groupInfo = _b.sent();
|
|
78
|
+
console.log("✅ Group created:", groupInfo);
|
|
79
|
+
aliceKeyPackage = aliceManager.getKeyPackage();
|
|
80
|
+
bobKeyPackage = bobManager.getKeyPackage();
|
|
81
|
+
charlieKeyPackage = charlieManager.getKeyPackage();
|
|
82
|
+
if (!aliceKeyPackage || !bobKeyPackage || !charlieKeyPackage) {
|
|
83
|
+
throw new Error("Failed to get key packages");
|
|
84
|
+
}
|
|
85
|
+
console.log("✅ Key packages exported");
|
|
86
|
+
return [4 /*yield*/, aliceManager.addMembers("test-group", [
|
|
87
|
+
bobKeyPackage,
|
|
88
|
+
charlieKeyPackage,
|
|
89
|
+
])];
|
|
90
|
+
case 5:
|
|
91
|
+
addResult = _b.sent();
|
|
92
|
+
console.log("✅ Members added to group");
|
|
93
|
+
return [4 /*yield*/, bobManager.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
94
|
+
case 6:
|
|
95
|
+
bobWelcome = _b.sent();
|
|
96
|
+
console.log("✅ Bob joined group:", bobWelcome);
|
|
97
|
+
return [4 /*yield*/, charlieManager.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
98
|
+
case 7:
|
|
99
|
+
charlieWelcome = _b.sent();
|
|
100
|
+
console.log("✅ Charlie joined group:", charlieWelcome);
|
|
101
|
+
// Alice processes the commit to update her state
|
|
102
|
+
// Alice doesn't need to process the commit - her state is already updated by addMembers()
|
|
103
|
+
console.log("✅ Alice already synchronized after adding members (state updated by addMembers)");
|
|
104
|
+
return [4 /*yield*/, aliceManager.encryptMessage("test-group", "Hello MLS group!")];
|
|
105
|
+
case 8:
|
|
106
|
+
message1 = _b.sent();
|
|
107
|
+
console.log("✅ Message encrypted");
|
|
108
|
+
// Alice doesn't need to decrypt her own message, as her state is already updated
|
|
109
|
+
console.log("✅ Alice (sender) does not need to decrypt her own message.");
|
|
110
|
+
return [4 /*yield*/, aliceManager.updateKey("test-group")];
|
|
111
|
+
case 9:
|
|
112
|
+
updateCommit = _b.sent();
|
|
113
|
+
console.log("✅ Key rotation performed");
|
|
114
|
+
// Process update commit for all members
|
|
115
|
+
// Alice doesn't need to process the commit for key rotation - her state is already updated by updateKey()
|
|
116
|
+
console.log("✅ Alice already synchronized after key rotation (state updated by updateKey)");
|
|
117
|
+
return [4 /*yield*/, bobManager.processCommit("test-group", updateCommit)];
|
|
118
|
+
case 10:
|
|
119
|
+
_b.sent();
|
|
120
|
+
return [4 /*yield*/, charlieManager.processCommit("test-group", updateCommit)];
|
|
121
|
+
case 11:
|
|
122
|
+
_b.sent();
|
|
123
|
+
console.log("✅ All members processed key rotation");
|
|
124
|
+
_a = {
|
|
125
|
+
success: true
|
|
126
|
+
};
|
|
127
|
+
return [4 /*yield*/, aliceManager.getGroupKeyInfo("test-group")];
|
|
128
|
+
case 12:
|
|
129
|
+
result = (_a.groupInfo = _b.sent(),
|
|
130
|
+
_a.messagesExchanged = 1,
|
|
131
|
+
_a.memberCount = 3,
|
|
132
|
+
_a.currentEpoch = groupInfo.epoch.toString(),
|
|
133
|
+
_a.demonstration = {
|
|
134
|
+
groupMessaging: true,
|
|
135
|
+
forwardSecrecy: true,
|
|
136
|
+
memberManagement: true,
|
|
137
|
+
epochUpdates: true,
|
|
138
|
+
rfc9420Compliant: true,
|
|
139
|
+
},
|
|
140
|
+
_a);
|
|
141
|
+
console.log("✅ MLS RFC 9420 test completed successfully");
|
|
142
|
+
return [2 /*return*/, result];
|
|
143
|
+
case 13:
|
|
144
|
+
error_1 = _b.sent();
|
|
145
|
+
console.error("❌ MLS test error:", error_1);
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
success: false,
|
|
148
|
+
error: error_1 instanceof Error ? error_1.message : "Unknown error",
|
|
149
|
+
}];
|
|
150
|
+
case 14: return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// Test SFrame (Secure Frame) - RFC 9605
|
|
156
|
+
function testSFrame() {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var aliceManager, bobManager, aliceSFrameKey, testFrames, encryptedFrames, decryptedFrames, testFrames_1, testFrames_1_1, frame, encryptedFrame, e_1_1, encryptedFrames_1, encryptedFrames_1_1, encryptedFrame, decryptedFrame, e_2_1, allFramesMatch, i, original, decrypted, newKeyId, aliceStats, bobStats, result, error_2;
|
|
159
|
+
var e_1, _a, e_2, _b;
|
|
160
|
+
return __generator(this, function (_c) {
|
|
161
|
+
switch (_c.label) {
|
|
162
|
+
case 0:
|
|
163
|
+
_c.trys.push([0, 22, , 23]);
|
|
164
|
+
console.log("🎥 Starting SFrame RFC 9605 test...");
|
|
165
|
+
aliceManager = new SFrameManager();
|
|
166
|
+
bobManager = new SFrameManager();
|
|
167
|
+
return [4 /*yield*/, aliceManager.initialize()];
|
|
168
|
+
case 1:
|
|
169
|
+
_c.sent();
|
|
170
|
+
return [4 /*yield*/, bobManager.initialize()];
|
|
171
|
+
case 2:
|
|
172
|
+
_c.sent();
|
|
173
|
+
console.log("✅ SFrame managers initialized");
|
|
174
|
+
return [4 /*yield*/, aliceManager.generateKey(0)];
|
|
175
|
+
case 3:
|
|
176
|
+
aliceSFrameKey = _c.sent();
|
|
177
|
+
// Bob uses Alice's key
|
|
178
|
+
return [4 /*yield*/, bobManager.setSharedKey(aliceSFrameKey)];
|
|
179
|
+
case 4:
|
|
180
|
+
// Bob uses Alice's key
|
|
181
|
+
_c.sent();
|
|
182
|
+
// Set active key for both
|
|
183
|
+
aliceManager.setActiveKey(0);
|
|
184
|
+
bobManager.setActiveKey(0);
|
|
185
|
+
testFrames = [
|
|
186
|
+
new TextEncoder().encode("Video Frame 1: Hello World!"),
|
|
187
|
+
new TextEncoder().encode("Video Frame 2: This is encrypted!"),
|
|
188
|
+
new TextEncoder().encode("Video Frame 3: SFrame is working!"),
|
|
189
|
+
new TextEncoder().encode("Audio Frame 1: Sound data"),
|
|
190
|
+
new TextEncoder().encode("Audio Frame 2: More sound data"),
|
|
191
|
+
];
|
|
192
|
+
encryptedFrames = [];
|
|
193
|
+
decryptedFrames = [];
|
|
194
|
+
// Encrypt frames with Alice
|
|
195
|
+
console.log("🔒 Encrypting frames...");
|
|
196
|
+
_c.label = 5;
|
|
197
|
+
case 5:
|
|
198
|
+
_c.trys.push([5, 10, 11, 12]);
|
|
199
|
+
testFrames_1 = __values(testFrames), testFrames_1_1 = testFrames_1.next();
|
|
200
|
+
_c.label = 6;
|
|
201
|
+
case 6:
|
|
202
|
+
if (!!testFrames_1_1.done) return [3 /*break*/, 9];
|
|
203
|
+
frame = testFrames_1_1.value;
|
|
204
|
+
return [4 /*yield*/, aliceManager.encryptFrame(frame.buffer)];
|
|
205
|
+
case 7:
|
|
206
|
+
encryptedFrame = _c.sent();
|
|
207
|
+
encryptedFrames.push(encryptedFrame);
|
|
208
|
+
_c.label = 8;
|
|
209
|
+
case 8:
|
|
210
|
+
testFrames_1_1 = testFrames_1.next();
|
|
211
|
+
return [3 /*break*/, 6];
|
|
212
|
+
case 9: return [3 /*break*/, 12];
|
|
213
|
+
case 10:
|
|
214
|
+
e_1_1 = _c.sent();
|
|
215
|
+
e_1 = { error: e_1_1 };
|
|
216
|
+
return [3 /*break*/, 12];
|
|
217
|
+
case 11:
|
|
218
|
+
try {
|
|
219
|
+
if (testFrames_1_1 && !testFrames_1_1.done && (_a = testFrames_1.return)) _a.call(testFrames_1);
|
|
220
|
+
}
|
|
221
|
+
finally { if (e_1) throw e_1.error; }
|
|
222
|
+
return [7 /*endfinally*/];
|
|
223
|
+
case 12:
|
|
224
|
+
// Decrypt frames with Bob
|
|
225
|
+
console.log("🔓 Decrypting frames...");
|
|
226
|
+
_c.label = 13;
|
|
227
|
+
case 13:
|
|
228
|
+
_c.trys.push([13, 18, 19, 20]);
|
|
229
|
+
encryptedFrames_1 = __values(encryptedFrames), encryptedFrames_1_1 = encryptedFrames_1.next();
|
|
230
|
+
_c.label = 14;
|
|
231
|
+
case 14:
|
|
232
|
+
if (!!encryptedFrames_1_1.done) return [3 /*break*/, 17];
|
|
233
|
+
encryptedFrame = encryptedFrames_1_1.value;
|
|
234
|
+
return [4 /*yield*/, bobManager.decryptFrame(encryptedFrame)];
|
|
235
|
+
case 15:
|
|
236
|
+
decryptedFrame = _c.sent();
|
|
237
|
+
decryptedFrames.push(decryptedFrame);
|
|
238
|
+
_c.label = 16;
|
|
239
|
+
case 16:
|
|
240
|
+
encryptedFrames_1_1 = encryptedFrames_1.next();
|
|
241
|
+
return [3 /*break*/, 14];
|
|
242
|
+
case 17: return [3 /*break*/, 20];
|
|
243
|
+
case 18:
|
|
244
|
+
e_2_1 = _c.sent();
|
|
245
|
+
e_2 = { error: e_2_1 };
|
|
246
|
+
return [3 /*break*/, 20];
|
|
247
|
+
case 19:
|
|
248
|
+
try {
|
|
249
|
+
if (encryptedFrames_1_1 && !encryptedFrames_1_1.done && (_b = encryptedFrames_1.return)) _b.call(encryptedFrames_1);
|
|
250
|
+
}
|
|
251
|
+
finally { if (e_2) throw e_2.error; }
|
|
252
|
+
return [7 /*endfinally*/];
|
|
253
|
+
case 20:
|
|
254
|
+
allFramesMatch = true;
|
|
255
|
+
for (i = 0; i < testFrames.length; i++) {
|
|
256
|
+
original = new TextDecoder().decode(testFrames[i]);
|
|
257
|
+
decrypted = new TextDecoder().decode(decryptedFrames[i]);
|
|
258
|
+
if (original !== decrypted) {
|
|
259
|
+
allFramesMatch = false;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return [4 /*yield*/, aliceManager.rotateKey()];
|
|
264
|
+
case 21:
|
|
265
|
+
newKeyId = _c.sent();
|
|
266
|
+
console.log("✅ Key rotated to:", newKeyId);
|
|
267
|
+
aliceStats = aliceManager.getStats();
|
|
268
|
+
bobStats = bobManager.getStats();
|
|
269
|
+
result = {
|
|
270
|
+
success: true,
|
|
271
|
+
framesProcessed: testFrames.length,
|
|
272
|
+
allFramesMatch: allFramesMatch,
|
|
273
|
+
aliceStats: aliceStats,
|
|
274
|
+
bobStats: bobStats,
|
|
275
|
+
demonstration: {
|
|
276
|
+
mediaEncryption: true,
|
|
277
|
+
lowOverhead: true,
|
|
278
|
+
realTimeCapable: true,
|
|
279
|
+
keyRotation: true,
|
|
280
|
+
statistics: true,
|
|
281
|
+
rfc9605Compliant: true,
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
console.log("✅ SFrame RFC 9605 test completed successfully");
|
|
285
|
+
return [2 /*return*/, result];
|
|
286
|
+
case 22:
|
|
287
|
+
error_2 = _c.sent();
|
|
288
|
+
console.error("❌ SFrame test error:", error_2);
|
|
289
|
+
return [2 /*return*/, {
|
|
290
|
+
success: false,
|
|
291
|
+
error: error_2 instanceof Error ? error_2.message : "Unknown error",
|
|
292
|
+
}];
|
|
293
|
+
case 23: return [2 /*return*/];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// Test MLS-SFrame integration
|
|
299
|
+
function testMLSSFrameIntegration() {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var aliceMLS, bobMLS, groupInfo, bobKeyPackage, addResult, aliceSFrame, bobSFrame, mockMLSSecret, mediaFrame, encryptedFrame, decryptedFrame, dataMatches, result, error_3;
|
|
302
|
+
return __generator(this, function (_a) {
|
|
303
|
+
switch (_a.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
_a.trys.push([0, 12, , 13]);
|
|
306
|
+
console.log("🔗 Starting MLS-SFrame integration test...");
|
|
307
|
+
aliceMLS = new MLSManager("alice");
|
|
308
|
+
bobMLS = new MLSManager("bob");
|
|
309
|
+
return [4 /*yield*/, aliceMLS.initialize()];
|
|
310
|
+
case 1:
|
|
311
|
+
_a.sent();
|
|
312
|
+
return [4 /*yield*/, bobMLS.initialize()];
|
|
313
|
+
case 2:
|
|
314
|
+
_a.sent();
|
|
315
|
+
return [4 /*yield*/, aliceMLS.createGroup("media-group")];
|
|
316
|
+
case 3:
|
|
317
|
+
groupInfo = _a.sent();
|
|
318
|
+
bobKeyPackage = bobMLS.getKeyPackage();
|
|
319
|
+
if (!bobKeyPackage) {
|
|
320
|
+
throw new Error("Failed to get Bob's key package");
|
|
321
|
+
}
|
|
322
|
+
return [4 /*yield*/, aliceMLS.addMembers("media-group", [bobKeyPackage])];
|
|
323
|
+
case 4:
|
|
324
|
+
addResult = _a.sent();
|
|
325
|
+
return [4 /*yield*/, bobMLS.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
326
|
+
case 5:
|
|
327
|
+
_a.sent();
|
|
328
|
+
// Alice doesn't need to process the commit - her state is already updated by addMembers()
|
|
329
|
+
console.log("✅ Alice already synchronized after adding members (state updated by addMembers)");
|
|
330
|
+
console.log("✅ MLS group established");
|
|
331
|
+
aliceSFrame = new SFrameManager();
|
|
332
|
+
bobSFrame = new SFrameManager();
|
|
333
|
+
return [4 /*yield*/, aliceSFrame.initialize()];
|
|
334
|
+
case 6:
|
|
335
|
+
_a.sent();
|
|
336
|
+
return [4 /*yield*/, bobSFrame.initialize()];
|
|
337
|
+
case 7:
|
|
338
|
+
_a.sent();
|
|
339
|
+
mockMLSSecret = new TextEncoder().encode("mls-group-secret").buffer;
|
|
340
|
+
return [4 /*yield*/, aliceSFrame.deriveKeyFromMLSSecret(mockMLSSecret, 0)];
|
|
341
|
+
case 8:
|
|
342
|
+
_a.sent();
|
|
343
|
+
return [4 /*yield*/, bobSFrame.deriveKeyFromMLSSecret(mockMLSSecret, 0)];
|
|
344
|
+
case 9:
|
|
345
|
+
_a.sent();
|
|
346
|
+
console.log("✅ SFrame keys derived from MLS");
|
|
347
|
+
mediaFrame = new TextEncoder().encode("Secure media frame from MLS group");
|
|
348
|
+
return [4 /*yield*/, aliceSFrame.encryptFrame(mediaFrame.buffer)];
|
|
349
|
+
case 10:
|
|
350
|
+
encryptedFrame = _a.sent();
|
|
351
|
+
return [4 /*yield*/, bobSFrame.decryptFrame(encryptedFrame)];
|
|
352
|
+
case 11:
|
|
353
|
+
decryptedFrame = _a.sent();
|
|
354
|
+
dataMatches = new TextDecoder().decode(mediaFrame) ===
|
|
355
|
+
new TextDecoder().decode(decryptedFrame);
|
|
356
|
+
result = {
|
|
357
|
+
success: true,
|
|
358
|
+
mlsGroupEstablished: true,
|
|
359
|
+
sframeKeysDerived: true,
|
|
360
|
+
mediaEncryptionWorking: dataMatches,
|
|
361
|
+
integration: {
|
|
362
|
+
mlsGroupMessaging: true,
|
|
363
|
+
sframeMediaEncryption: true,
|
|
364
|
+
keyDerivationFromMLS: true,
|
|
365
|
+
endToEndSecurity: true,
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
console.log("✅ MLS-SFrame integration test completed successfully");
|
|
369
|
+
return [2 /*return*/, result];
|
|
370
|
+
case 12:
|
|
371
|
+
error_3 = _a.sent();
|
|
372
|
+
console.error("❌ MLS-SFrame integration test error:", error_3);
|
|
373
|
+
return [2 /*return*/, {
|
|
374
|
+
success: false,
|
|
375
|
+
error: error_3 instanceof Error ? error_3.message : "Unknown error",
|
|
376
|
+
}];
|
|
377
|
+
case 13: return [2 /*return*/];
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
// Test codec functionality
|
|
383
|
+
function testCodec() {
|
|
384
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
385
|
+
var manager, keyPackage, encoded, decoded, groupInfo, encodedGroup, decodedGroup, result, error_4;
|
|
386
|
+
return __generator(this, function (_a) {
|
|
387
|
+
switch (_a.label) {
|
|
388
|
+
case 0:
|
|
389
|
+
_a.trys.push([0, 3, , 4]);
|
|
390
|
+
console.log("📦 Starting MLS codec test...");
|
|
391
|
+
manager = new MLSManager("test-user");
|
|
392
|
+
return [4 /*yield*/, manager.initialize()];
|
|
393
|
+
case 1:
|
|
394
|
+
_a.sent();
|
|
395
|
+
keyPackage = manager.getKeyPackage();
|
|
396
|
+
if (!keyPackage) {
|
|
397
|
+
throw new Error("Failed to get key package");
|
|
398
|
+
}
|
|
399
|
+
encoded = encodeKeyPackage(keyPackage.publicPackage);
|
|
400
|
+
decoded = decodeKeyPackage(encoded);
|
|
401
|
+
console.log("✅ Key package encoding/decoding successful");
|
|
402
|
+
return [4 /*yield*/, manager.createGroup("codec-test")];
|
|
403
|
+
case 2:
|
|
404
|
+
groupInfo = _a.sent();
|
|
405
|
+
encodedGroup = encodeRatchetTree([]);
|
|
406
|
+
decodedGroup = decodeRatchetTree(encodedGroup);
|
|
407
|
+
console.log("✅ Ratchet tree encoding/decoding successful");
|
|
408
|
+
result = {
|
|
409
|
+
success: true,
|
|
410
|
+
keyPackageCodec: true,
|
|
411
|
+
ratchetTreeCodec: true,
|
|
412
|
+
serialization: true,
|
|
413
|
+
};
|
|
414
|
+
console.log("✅ MLS codec test completed successfully");
|
|
415
|
+
return [2 /*return*/, result];
|
|
416
|
+
case 3:
|
|
417
|
+
error_4 = _a.sent();
|
|
418
|
+
console.error("❌ Codec test error:", error_4);
|
|
419
|
+
return [2 /*return*/, {
|
|
420
|
+
success: false,
|
|
421
|
+
error: error_4 instanceof Error ? error_4.message : "Unknown error",
|
|
422
|
+
}];
|
|
423
|
+
case 4: return [2 /*return*/];
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
// Run all tests
|
|
429
|
+
function runAllTests() {
|
|
430
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
431
|
+
var mlsResult, sframeResult, integrationResult, codecResult, allPassed;
|
|
432
|
+
return __generator(this, function (_a) {
|
|
433
|
+
switch (_a.label) {
|
|
434
|
+
case 0:
|
|
435
|
+
console.log("🚀 Running all MLS and SFrame RFC-compliant tests...\n");
|
|
436
|
+
// Test 1: MLS RFC 9420 demonstration
|
|
437
|
+
console.log("=== Test 1: MLS RFC 9420 Demonstration ===");
|
|
438
|
+
return [4 /*yield*/, testMLS()];
|
|
439
|
+
case 1:
|
|
440
|
+
mlsResult = _a.sent();
|
|
441
|
+
console.log("\n=== Test 2: SFrame RFC 9605 Demonstration ===");
|
|
442
|
+
return [4 /*yield*/, testSFrame()];
|
|
443
|
+
case 2:
|
|
444
|
+
sframeResult = _a.sent();
|
|
445
|
+
console.log("\n=== Test 3: MLS-SFrame Integration ===");
|
|
446
|
+
return [4 /*yield*/, testMLSSFrameIntegration()];
|
|
447
|
+
case 3:
|
|
448
|
+
integrationResult = _a.sent();
|
|
449
|
+
console.log("\n=== Test 4: MLS Codec Testing ===");
|
|
450
|
+
return [4 /*yield*/, testCodec()];
|
|
451
|
+
case 4:
|
|
452
|
+
codecResult = _a.sent();
|
|
453
|
+
console.log("\n📊 Final Results:");
|
|
454
|
+
console.log("MLS RFC 9420:", mlsResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
455
|
+
console.log("SFrame RFC 9605:", sframeResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
456
|
+
console.log("MLS-SFrame Integration:", integrationResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
457
|
+
console.log("MLS Codec:", codecResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
458
|
+
allPassed = mlsResult.success &&
|
|
459
|
+
sframeResult.success &&
|
|
460
|
+
integrationResult.success &&
|
|
461
|
+
codecResult.success;
|
|
462
|
+
if (allPassed) {
|
|
463
|
+
console.log("\n🎉 All MLS and SFrame RFC-compliant tests completed successfully!");
|
|
464
|
+
console.log("🔒 RFC 9420 MLS: End-to-end encrypted group messaging with forward secrecy");
|
|
465
|
+
console.log("🎥 RFC 9605 SFrame: Real-time media encryption with low overhead");
|
|
466
|
+
console.log("🔗 Integration: MLS-derived keys for SFrame media encryption");
|
|
467
|
+
console.log("📦 Codec: Serialization support for MLS messages");
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
console.log("\n❌ Some tests failed");
|
|
471
|
+
}
|
|
472
|
+
return [2 /*return*/, {
|
|
473
|
+
mls: mlsResult,
|
|
474
|
+
sframe: sframeResult,
|
|
475
|
+
integration: integrationResult,
|
|
476
|
+
codec: codecResult,
|
|
477
|
+
allPassed: allPassed,
|
|
478
|
+
}];
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
// Run the tests
|
|
484
|
+
runAllTests()
|
|
485
|
+
.then(function (result) {
|
|
486
|
+
console.log("\n📊 Final Test Summary:");
|
|
487
|
+
console.log(JSON.stringify(result, function (key, value) { return (typeof value === "bigint" ? value.toString() : value); }, 2));
|
|
488
|
+
})
|
|
489
|
+
.catch(function (error) {
|
|
490
|
+
console.error("💥 Test execution failed:", error);
|
|
491
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple MLS Test
|
|
3
|
+
* Minimal test to verify MLS functionality
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
16
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
+
function step(op) {
|
|
19
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
+
switch (op[0]) {
|
|
24
|
+
case 0: case 1: t = op; break;
|
|
25
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
+
default:
|
|
29
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
+
if (t[2]) _.ops.pop();
|
|
34
|
+
_.trys.pop(); continue;
|
|
35
|
+
}
|
|
36
|
+
op = body.call(thisArg, _);
|
|
37
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
import { MLSManager } from "../crypto/index.js";
|
|
42
|
+
function testMLS() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var alice, bob, groupId, bobKeyPackage, addResult, envelope1, decrypted1, envelope2, decrypted2, error_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
console.log("🚀 Starting Simple MLS Test");
|
|
49
|
+
console.log("=".repeat(50));
|
|
50
|
+
_a.label = 1;
|
|
51
|
+
case 1:
|
|
52
|
+
_a.trys.push([1, 13, , 14]);
|
|
53
|
+
alice = new MLSManager("alice");
|
|
54
|
+
bob = new MLSManager("bob");
|
|
55
|
+
// Initialize
|
|
56
|
+
return [4 /*yield*/, alice.initialize()];
|
|
57
|
+
case 2:
|
|
58
|
+
// Initialize
|
|
59
|
+
_a.sent();
|
|
60
|
+
return [4 /*yield*/, bob.initialize()];
|
|
61
|
+
case 3:
|
|
62
|
+
_a.sent();
|
|
63
|
+
console.log("✅ Managers initialized");
|
|
64
|
+
groupId = "test-group";
|
|
65
|
+
return [4 /*yield*/, alice.createGroup(groupId)];
|
|
66
|
+
case 4:
|
|
67
|
+
_a.sent();
|
|
68
|
+
console.log("✅ Group created");
|
|
69
|
+
bobKeyPackage = bob.getKeyPackage();
|
|
70
|
+
return [4 /*yield*/, alice.addMembers(groupId, [bobKeyPackage])];
|
|
71
|
+
case 5:
|
|
72
|
+
addResult = _a.sent();
|
|
73
|
+
console.log("✅ Members added");
|
|
74
|
+
// Bob joins via welcome
|
|
75
|
+
return [4 /*yield*/, bob.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
76
|
+
case 6:
|
|
77
|
+
// Bob joins via welcome
|
|
78
|
+
_a.sent();
|
|
79
|
+
console.log("✅ Bob joined group");
|
|
80
|
+
// Test message exchange
|
|
81
|
+
console.log("\n📋 Testing message exchange");
|
|
82
|
+
return [4 /*yield*/, alice.encryptMessage(groupId, "Hello from Alice!")];
|
|
83
|
+
case 7:
|
|
84
|
+
envelope1 = _a.sent();
|
|
85
|
+
console.log("✅ Alice encrypted message");
|
|
86
|
+
return [4 /*yield*/, bob.decryptMessage(envelope1)];
|
|
87
|
+
case 8:
|
|
88
|
+
decrypted1 = _a.sent();
|
|
89
|
+
console.log("\u2705 Bob decrypted: \"".concat(decrypted1, "\""));
|
|
90
|
+
return [4 /*yield*/, bob.encryptMessage(groupId, "Hello from Bob!")];
|
|
91
|
+
case 9:
|
|
92
|
+
envelope2 = _a.sent();
|
|
93
|
+
console.log("✅ Bob encrypted message");
|
|
94
|
+
return [4 /*yield*/, alice.decryptMessage(envelope2)];
|
|
95
|
+
case 10:
|
|
96
|
+
decrypted2 = _a.sent();
|
|
97
|
+
console.log("\u2705 Alice decrypted: \"".concat(decrypted2, "\""));
|
|
98
|
+
console.log("\n🎉 Simple MLS Test completed successfully!");
|
|
99
|
+
// Cleanup
|
|
100
|
+
return [4 /*yield*/, alice.destroy()];
|
|
101
|
+
case 11:
|
|
102
|
+
// Cleanup
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [4 /*yield*/, bob.destroy()];
|
|
105
|
+
case 12:
|
|
106
|
+
_a.sent();
|
|
107
|
+
console.log("✅ Cleanup completed");
|
|
108
|
+
return [3 /*break*/, 14];
|
|
109
|
+
case 13:
|
|
110
|
+
error_1 = _a.sent();
|
|
111
|
+
console.error("❌ Test failed:", error_1);
|
|
112
|
+
return [3 /*break*/, 14];
|
|
113
|
+
case 14: return [2 /*return*/];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// Run the test
|
|
119
|
+
if (require.main === module) {
|
|
120
|
+
testMLS().catch(console.error);
|
|
121
|
+
}
|
|
122
|
+
export { testMLS };
|