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,240 @@
|
|
|
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
|
+
// Double Ratchet Protocol test
|
|
38
|
+
import { demonstrateDoubleRatchet, initializeDoubleRatchet, doubleRatchetEncrypt, doubleRatchetDecrypt, serializeDoubleRatchetState, } from "../crypto/index.js";
|
|
39
|
+
// Test Double Ratchet Protocol
|
|
40
|
+
function testDoubleRatchet() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
+
var result, aliceStateSerialized, error_1;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
_a.trys.push([0, 2, , 3]);
|
|
47
|
+
console.log("🔄 Starting Double Ratchet Protocol test...");
|
|
48
|
+
return [4 /*yield*/, demonstrateDoubleRatchet()];
|
|
49
|
+
case 1:
|
|
50
|
+
result = _a.sent();
|
|
51
|
+
if (result.success) {
|
|
52
|
+
console.log("✅ Double Ratchet Protocol test successful!");
|
|
53
|
+
console.log("Messages exchanged:", result.messagesExchanged);
|
|
54
|
+
console.log("Forward secrecy:", result.demonstration.forwardSecrecy);
|
|
55
|
+
console.log("Out-of-order handling:", result.demonstration.outOfOrderHandling);
|
|
56
|
+
console.log("DH ratcheting:", result.demonstration.dhRatcheting);
|
|
57
|
+
console.log("Chain key updating:", result.demonstration.chainKeyUpdating);
|
|
58
|
+
// Test individual functions
|
|
59
|
+
console.log("\n🧪 Testing individual Double Ratchet functions...");
|
|
60
|
+
aliceStateSerialized = result.aliceState;
|
|
61
|
+
console.log("✅ Alice state serialized:", aliceStateSerialized.substring(0, 100) + "...");
|
|
62
|
+
// Test conversation
|
|
63
|
+
console.log("✅ Conversation messages:", result.conversation.length);
|
|
64
|
+
result.conversation.forEach(function (msg, index) {
|
|
65
|
+
console.log(" Message ".concat(index + 1, ": ").concat(msg.from, " \u2192 Message #").concat(msg.envelope.messageNumber));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.log("❌ Double Ratchet Protocol test failed");
|
|
70
|
+
}
|
|
71
|
+
return [2 /*return*/, result];
|
|
72
|
+
case 2:
|
|
73
|
+
error_1 = _a.sent();
|
|
74
|
+
console.error("❌ Double Ratchet Protocol test error:", error_1);
|
|
75
|
+
return [2 /*return*/, {
|
|
76
|
+
success: false,
|
|
77
|
+
error: error_1 instanceof Error ? error_1.message : "Unknown error",
|
|
78
|
+
}];
|
|
79
|
+
case 3: return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Test interactive Double Ratchet messaging
|
|
85
|
+
function testInteractiveDoubleRatchet() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var _a, initializeSignalUser, getSignalPublicKeyBundle, performSignalX3DHKeyExchange, alice, bob, bobBundle, exchangeResult, aliceState, bobState, messages, conversation, i, sender, senderState, receiverState, envelope, decrypted, aliceSerialized, bobSerialized, error_2;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
_b.trys.push([0, 15, , 16]);
|
|
92
|
+
console.log("🔄 Starting Interactive Double Ratchet test...");
|
|
93
|
+
return [4 /*yield*/, import("../crypto/signal-protocol")];
|
|
94
|
+
case 1:
|
|
95
|
+
_a = _b.sent(), initializeSignalUser = _a.initializeSignalUser, getSignalPublicKeyBundle = _a.getSignalPublicKeyBundle, performSignalX3DHKeyExchange = _a.performSignalX3DHKeyExchange;
|
|
96
|
+
return [4 /*yield*/, initializeSignalUser("Alice")];
|
|
97
|
+
case 2:
|
|
98
|
+
alice = _b.sent();
|
|
99
|
+
return [4 /*yield*/, initializeSignalUser("Bob")];
|
|
100
|
+
case 3:
|
|
101
|
+
bob = _b.sent();
|
|
102
|
+
return [4 /*yield*/, getSignalPublicKeyBundle(bob)];
|
|
103
|
+
case 4:
|
|
104
|
+
bobBundle = _b.sent();
|
|
105
|
+
return [4 /*yield*/, performSignalX3DHKeyExchange(alice, bobBundle)];
|
|
106
|
+
case 5:
|
|
107
|
+
exchangeResult = _b.sent();
|
|
108
|
+
console.log("✅ X3DH key exchange completed");
|
|
109
|
+
return [4 /*yield*/, initializeDoubleRatchet(exchangeResult.masterSecret, true)];
|
|
110
|
+
case 6:
|
|
111
|
+
aliceState = _b.sent();
|
|
112
|
+
return [4 /*yield*/, initializeDoubleRatchet(exchangeResult.masterSecret, false)];
|
|
113
|
+
case 7:
|
|
114
|
+
bobState = _b.sent();
|
|
115
|
+
console.log("✅ Double Ratchet states initialized");
|
|
116
|
+
messages = [
|
|
117
|
+
"Hello Bob! This is our first Double Ratchet message! 🔒",
|
|
118
|
+
"Hi Alice! The Double Ratchet is working perfectly! 🎉",
|
|
119
|
+
"This is message 3 with forward secrecy! 🛡️",
|
|
120
|
+
"And this is message 4 - each with a unique key! 🔑",
|
|
121
|
+
];
|
|
122
|
+
conversation = [];
|
|
123
|
+
i = 0;
|
|
124
|
+
_b.label = 8;
|
|
125
|
+
case 8:
|
|
126
|
+
if (!(i < messages.length)) return [3 /*break*/, 12];
|
|
127
|
+
sender = i % 2 === 0 ? "Alice" : "Bob";
|
|
128
|
+
senderState = sender === "Alice" ? aliceState : bobState;
|
|
129
|
+
receiverState = sender === "Alice" ? bobState : aliceState;
|
|
130
|
+
console.log("\n\uD83D\uDCE4 ".concat(sender, " sending message ").concat(i + 1, ": \"").concat(messages[i], "\""));
|
|
131
|
+
return [4 /*yield*/, doubleRatchetEncrypt(senderState, messages[i])];
|
|
132
|
+
case 9:
|
|
133
|
+
envelope = _b.sent();
|
|
134
|
+
console.log("\u2705 ".concat(sender, " encrypted message #").concat(envelope.messageNumber));
|
|
135
|
+
return [4 /*yield*/, doubleRatchetDecrypt(receiverState, envelope)];
|
|
136
|
+
case 10:
|
|
137
|
+
decrypted = _b.sent();
|
|
138
|
+
console.log("\u2705 ".concat(sender === "Alice" ? "Bob" : "Alice", " decrypted: \"").concat(decrypted, "\""));
|
|
139
|
+
// Verify
|
|
140
|
+
if (decrypted === messages[i]) {
|
|
141
|
+
console.log("\u2705 Message ".concat(i + 1, " verified successfully"));
|
|
142
|
+
conversation.push({
|
|
143
|
+
sender: sender,
|
|
144
|
+
receiver: sender === "Alice" ? "Bob" : "Alice",
|
|
145
|
+
original: messages[i],
|
|
146
|
+
decrypted: decrypted,
|
|
147
|
+
messageNumber: envelope.messageNumber,
|
|
148
|
+
verified: true,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.log("\u274C Message ".concat(i + 1, " verification failed"));
|
|
153
|
+
conversation.push({
|
|
154
|
+
sender: sender,
|
|
155
|
+
receiver: sender === "Alice" ? "Bob" : "Alice",
|
|
156
|
+
original: messages[i],
|
|
157
|
+
decrypted: decrypted,
|
|
158
|
+
messageNumber: envelope.messageNumber,
|
|
159
|
+
verified: false,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
_b.label = 11;
|
|
163
|
+
case 11:
|
|
164
|
+
i++;
|
|
165
|
+
return [3 /*break*/, 8];
|
|
166
|
+
case 12: return [4 /*yield*/, serializeDoubleRatchetState(aliceState)];
|
|
167
|
+
case 13:
|
|
168
|
+
aliceSerialized = _b.sent();
|
|
169
|
+
return [4 /*yield*/, serializeDoubleRatchetState(bobState)];
|
|
170
|
+
case 14:
|
|
171
|
+
bobSerialized = _b.sent();
|
|
172
|
+
console.log("\n📊 Interactive Double Ratchet test results:");
|
|
173
|
+
console.log("Messages exchanged: ".concat(conversation.length));
|
|
174
|
+
console.log("All messages verified: ".concat(conversation.every(function (msg) { return msg.verified; })));
|
|
175
|
+
console.log("Alice state serialized: ".concat(aliceSerialized.length, " characters"));
|
|
176
|
+
console.log("Bob state serialized: ".concat(bobSerialized.length, " characters"));
|
|
177
|
+
return [2 /*return*/, {
|
|
178
|
+
success: true,
|
|
179
|
+
messagesExchanged: conversation.length,
|
|
180
|
+
allVerified: conversation.every(function (msg) { return msg.verified; }),
|
|
181
|
+
conversation: conversation,
|
|
182
|
+
aliceState: aliceSerialized,
|
|
183
|
+
bobState: bobSerialized,
|
|
184
|
+
}];
|
|
185
|
+
case 15:
|
|
186
|
+
error_2 = _b.sent();
|
|
187
|
+
console.error("❌ Interactive Double Ratchet test error:", error_2);
|
|
188
|
+
return [2 /*return*/, {
|
|
189
|
+
success: false,
|
|
190
|
+
error: error_2 instanceof Error ? error_2.message : "Unknown error",
|
|
191
|
+
}];
|
|
192
|
+
case 16: return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
// Run the tests
|
|
198
|
+
function runAllTests() {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var basicResult, interactiveResult;
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
switch (_a.label) {
|
|
203
|
+
case 0:
|
|
204
|
+
console.log("🚀 Running all Double Ratchet tests...\n");
|
|
205
|
+
// Test 1: Basic demonstration
|
|
206
|
+
console.log("=== Test 1: Basic Double Ratchet Demonstration ===");
|
|
207
|
+
return [4 /*yield*/, testDoubleRatchet()];
|
|
208
|
+
case 1:
|
|
209
|
+
basicResult = _a.sent();
|
|
210
|
+
console.log("\n=== Test 2: Interactive Double Ratchet Messaging ===");
|
|
211
|
+
return [4 /*yield*/, testInteractiveDoubleRatchet()];
|
|
212
|
+
case 2:
|
|
213
|
+
interactiveResult = _a.sent();
|
|
214
|
+
console.log("\n📊 Final Results:");
|
|
215
|
+
console.log("Basic test:", basicResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
216
|
+
console.log("Interactive test:", interactiveResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
217
|
+
if (basicResult.success && interactiveResult.success) {
|
|
218
|
+
console.log("\n🎉 All Double Ratchet tests completed successfully!");
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
console.log("\n❌ Some tests failed");
|
|
222
|
+
}
|
|
223
|
+
return [2 /*return*/, {
|
|
224
|
+
basic: basicResult,
|
|
225
|
+
interactive: interactiveResult,
|
|
226
|
+
allPassed: basicResult.success && interactiveResult.success,
|
|
227
|
+
}];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
// Run the tests
|
|
233
|
+
runAllTests()
|
|
234
|
+
.then(function (result) {
|
|
235
|
+
console.log("\n📊 Final Test Summary:");
|
|
236
|
+
console.log(JSON.stringify(result, null, 2));
|
|
237
|
+
})
|
|
238
|
+
.catch(function (error) {
|
|
239
|
+
console.error("💥 Test execution failed:", error);
|
|
240
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MLS 3-Member Test
|
|
3
|
+
* Test specifico per gruppi di 3 membri
|
|
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 testMLS3Members() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
+
var alice, bob, charlie, groupId, bobKeyPackage, charlieKeyPackage, addResult, aliceInfo, bobInfo, charlieInfo, envelope1, bobDecrypted1, charlieDecrypted1, envelope2, aliceDecrypted2, charlieDecrypted2, envelope3, aliceDecrypted3, bobDecrypted3, error_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
console.log("🚀 Starting MLS 3-Member Test");
|
|
49
|
+
console.log("=".repeat(50));
|
|
50
|
+
_a.label = 1;
|
|
51
|
+
case 1:
|
|
52
|
+
_a.trys.push([1, 24, , 25]);
|
|
53
|
+
alice = new MLSManager("alice");
|
|
54
|
+
bob = new MLSManager("bob");
|
|
55
|
+
charlie = new MLSManager("charlie");
|
|
56
|
+
// Initialize
|
|
57
|
+
return [4 /*yield*/, alice.initialize()];
|
|
58
|
+
case 2:
|
|
59
|
+
// Initialize
|
|
60
|
+
_a.sent();
|
|
61
|
+
return [4 /*yield*/, bob.initialize()];
|
|
62
|
+
case 3:
|
|
63
|
+
_a.sent();
|
|
64
|
+
return [4 /*yield*/, charlie.initialize()];
|
|
65
|
+
case 4:
|
|
66
|
+
_a.sent();
|
|
67
|
+
console.log("✅ All managers initialized");
|
|
68
|
+
groupId = "test-3-members";
|
|
69
|
+
return [4 /*yield*/, alice.createGroup(groupId)];
|
|
70
|
+
case 5:
|
|
71
|
+
_a.sent();
|
|
72
|
+
console.log("✅ Group created by Alice");
|
|
73
|
+
bobKeyPackage = bob.getKeyPackage();
|
|
74
|
+
charlieKeyPackage = charlie.getKeyPackage();
|
|
75
|
+
console.log("➕ Adding Bob and Charlie to group...");
|
|
76
|
+
return [4 /*yield*/, alice.addMembers(groupId, [
|
|
77
|
+
bobKeyPackage,
|
|
78
|
+
charlieKeyPackage,
|
|
79
|
+
])];
|
|
80
|
+
case 6:
|
|
81
|
+
addResult = _a.sent();
|
|
82
|
+
console.log("✅ Members added by Alice");
|
|
83
|
+
// Bob and Charlie join via welcome
|
|
84
|
+
return [4 /*yield*/, bob.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
85
|
+
case 7:
|
|
86
|
+
// Bob and Charlie join via welcome
|
|
87
|
+
_a.sent();
|
|
88
|
+
return [4 /*yield*/, charlie.processWelcome(addResult.welcome, addResult.ratchetTree)];
|
|
89
|
+
case 8:
|
|
90
|
+
_a.sent();
|
|
91
|
+
console.log("✅ Bob and Charlie joined group");
|
|
92
|
+
return [4 /*yield*/, alice.getGroupKeyInfo(groupId)];
|
|
93
|
+
case 9:
|
|
94
|
+
aliceInfo = _a.sent();
|
|
95
|
+
return [4 /*yield*/, bob.getGroupKeyInfo(groupId)];
|
|
96
|
+
case 10:
|
|
97
|
+
bobInfo = _a.sent();
|
|
98
|
+
return [4 /*yield*/, charlie.getGroupKeyInfo(groupId)];
|
|
99
|
+
case 11:
|
|
100
|
+
charlieInfo = _a.sent();
|
|
101
|
+
console.log("\uD83D\uDCCA Epoch verification - Alice: ".concat(aliceInfo === null || aliceInfo === void 0 ? void 0 : aliceInfo.epoch, ", Bob: ").concat(bobInfo === null || bobInfo === void 0 ? void 0 : bobInfo.epoch, ", Charlie: ").concat(charlieInfo === null || charlieInfo === void 0 ? void 0 : charlieInfo.epoch));
|
|
102
|
+
if ((aliceInfo === null || aliceInfo === void 0 ? void 0 : aliceInfo.epoch) === (bobInfo === null || bobInfo === void 0 ? void 0 : bobInfo.epoch) &&
|
|
103
|
+
(bobInfo === null || bobInfo === void 0 ? void 0 : bobInfo.epoch) === (charlieInfo === null || charlieInfo === void 0 ? void 0 : charlieInfo.epoch)) {
|
|
104
|
+
console.log("\u2705 All 3 members synchronized at epoch ".concat(aliceInfo === null || aliceInfo === void 0 ? void 0 : aliceInfo.epoch));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
console.log("\u26A0\uFE0F WARNING: Members at different epochs");
|
|
108
|
+
}
|
|
109
|
+
// Test message exchange
|
|
110
|
+
console.log("\n📋 Testing message exchange with 3 members");
|
|
111
|
+
// Alice sends message
|
|
112
|
+
console.log("💬 Alice sending message...");
|
|
113
|
+
return [4 /*yield*/, alice.encryptMessage(groupId, "Hello from Alice to Bob and Charlie!")];
|
|
114
|
+
case 12:
|
|
115
|
+
envelope1 = _a.sent();
|
|
116
|
+
console.log("✅ Alice encrypted message");
|
|
117
|
+
return [4 /*yield*/, bob.decryptMessage(envelope1)];
|
|
118
|
+
case 13:
|
|
119
|
+
bobDecrypted1 = _a.sent();
|
|
120
|
+
console.log("\u2705 Bob decrypted: \"".concat(bobDecrypted1, "\""));
|
|
121
|
+
return [4 /*yield*/, charlie.decryptMessage(envelope1)];
|
|
122
|
+
case 14:
|
|
123
|
+
charlieDecrypted1 = _a.sent();
|
|
124
|
+
console.log("\u2705 Charlie decrypted: \"".concat(charlieDecrypted1, "\""));
|
|
125
|
+
// Bob sends message
|
|
126
|
+
console.log("\n💬 Bob sending message...");
|
|
127
|
+
return [4 /*yield*/, bob.encryptMessage(groupId, "Hello from Bob to Alice and Charlie!")];
|
|
128
|
+
case 15:
|
|
129
|
+
envelope2 = _a.sent();
|
|
130
|
+
console.log("✅ Bob encrypted message");
|
|
131
|
+
return [4 /*yield*/, alice.decryptMessage(envelope2)];
|
|
132
|
+
case 16:
|
|
133
|
+
aliceDecrypted2 = _a.sent();
|
|
134
|
+
console.log("\u2705 Alice decrypted: \"".concat(aliceDecrypted2, "\""));
|
|
135
|
+
return [4 /*yield*/, charlie.decryptMessage(envelope2)];
|
|
136
|
+
case 17:
|
|
137
|
+
charlieDecrypted2 = _a.sent();
|
|
138
|
+
console.log("\u2705 Charlie decrypted: \"".concat(charlieDecrypted2, "\""));
|
|
139
|
+
// Charlie sends message
|
|
140
|
+
console.log("\n💬 Charlie sending message...");
|
|
141
|
+
return [4 /*yield*/, charlie.encryptMessage(groupId, "Hello from Charlie to Alice and Bob!")];
|
|
142
|
+
case 18:
|
|
143
|
+
envelope3 = _a.sent();
|
|
144
|
+
console.log("✅ Charlie encrypted message");
|
|
145
|
+
return [4 /*yield*/, alice.decryptMessage(envelope3)];
|
|
146
|
+
case 19:
|
|
147
|
+
aliceDecrypted3 = _a.sent();
|
|
148
|
+
console.log("\u2705 Alice decrypted: \"".concat(aliceDecrypted3, "\""));
|
|
149
|
+
return [4 /*yield*/, bob.decryptMessage(envelope3)];
|
|
150
|
+
case 20:
|
|
151
|
+
bobDecrypted3 = _a.sent();
|
|
152
|
+
console.log("\u2705 Bob decrypted: \"".concat(bobDecrypted3, "\""));
|
|
153
|
+
console.log("\n🎉 MLS 3-Member Test completed successfully!");
|
|
154
|
+
console.log("✅ Group creation with 3 members");
|
|
155
|
+
console.log("✅ Bidirectional encrypted messaging");
|
|
156
|
+
console.log("✅ All members can send and receive messages");
|
|
157
|
+
// Cleanup
|
|
158
|
+
return [4 /*yield*/, alice.destroy()];
|
|
159
|
+
case 21:
|
|
160
|
+
// Cleanup
|
|
161
|
+
_a.sent();
|
|
162
|
+
return [4 /*yield*/, bob.destroy()];
|
|
163
|
+
case 22:
|
|
164
|
+
_a.sent();
|
|
165
|
+
return [4 /*yield*/, charlie.destroy()];
|
|
166
|
+
case 23:
|
|
167
|
+
_a.sent();
|
|
168
|
+
console.log("✅ Cleanup completed");
|
|
169
|
+
return [3 /*break*/, 25];
|
|
170
|
+
case 24:
|
|
171
|
+
error_1 = _a.sent();
|
|
172
|
+
console.error("❌ Test failed:", error_1);
|
|
173
|
+
return [3 /*break*/, 25];
|
|
174
|
+
case 25: return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// Run the test
|
|
180
|
+
if (require.main === module) {
|
|
181
|
+
testMLS3Members().catch(console.error);
|
|
182
|
+
}
|
|
183
|
+
export { testMLS3Members };
|