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,466 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SFrame (Secure Frame) Manager
|
|
3
|
+
* End-to-end encryption for real-time media frames (audio/video)
|
|
4
|
+
* Designed for low overhead and high performance
|
|
5
|
+
*
|
|
6
|
+
* SFrame adds ~10 bytes per frame overhead
|
|
7
|
+
* Compatible with WebRTC Insertable Streams API
|
|
8
|
+
*/
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
19
|
+
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);
|
|
20
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
21
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
22
|
+
function step(op) {
|
|
23
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
24
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
25
|
+
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;
|
|
26
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
27
|
+
switch (op[0]) {
|
|
28
|
+
case 0: case 1: t = op; break;
|
|
29
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
30
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
31
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
32
|
+
default:
|
|
33
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
34
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
35
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
36
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
37
|
+
if (t[2]) _.ops.pop();
|
|
38
|
+
_.trys.pop(); continue;
|
|
39
|
+
}
|
|
40
|
+
op = body.call(thisArg, _);
|
|
41
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
42
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var SFrameManager = /** @class */ (function () {
|
|
46
|
+
function SFrameManager() {
|
|
47
|
+
this.keys = new Map();
|
|
48
|
+
this.currentKeyId = 0;
|
|
49
|
+
this.frameCounter = 0;
|
|
50
|
+
this.initialized = false;
|
|
51
|
+
console.log("🎥 [SFrame] Manager created");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Initialize the SFrame manager
|
|
55
|
+
*/
|
|
56
|
+
SFrameManager.prototype.initialize = function () {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var error_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (this.initialized) {
|
|
63
|
+
console.warn("[SFrame] Already initialized");
|
|
64
|
+
return [2 /*return*/];
|
|
65
|
+
}
|
|
66
|
+
_a.label = 1;
|
|
67
|
+
case 1:
|
|
68
|
+
_a.trys.push([1, 3, , 4]);
|
|
69
|
+
console.log("🔐 [SFrame] Initializing...");
|
|
70
|
+
// Generate initial key
|
|
71
|
+
return [4 /*yield*/, this.generateKey(0)];
|
|
72
|
+
case 2:
|
|
73
|
+
// Generate initial key
|
|
74
|
+
_a.sent();
|
|
75
|
+
this.initialized = true;
|
|
76
|
+
console.log("✅ [SFrame] Initialized successfully");
|
|
77
|
+
return [3 /*break*/, 4];
|
|
78
|
+
case 3:
|
|
79
|
+
error_1 = _a.sent();
|
|
80
|
+
console.error("❌ [SFrame] Initialization failed:", error_1);
|
|
81
|
+
throw new Error("SFrame initialization failed: ".concat(error_1 instanceof Error ? error_1.message : String(error_1)));
|
|
82
|
+
case 4: return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Generate a new SFrame encryption key
|
|
89
|
+
*/
|
|
90
|
+
SFrameManager.prototype.generateKey = function (keyId) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var key, salt, sframeKey, error_2;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
_a.trys.push([0, 2, , 3]);
|
|
97
|
+
console.log("\uD83D\uDD11 [SFrame] Generating key ".concat(keyId, "..."));
|
|
98
|
+
return [4 /*yield*/, crypto.subtle.generateKey({
|
|
99
|
+
name: "AES-GCM",
|
|
100
|
+
length: 128, // 128-bit for performance, 256-bit for maximum security
|
|
101
|
+
}, false, // Not extractable for security
|
|
102
|
+
["encrypt", "decrypt"])];
|
|
103
|
+
case 1:
|
|
104
|
+
key = _a.sent();
|
|
105
|
+
salt = crypto.getRandomValues(new Uint8Array(16));
|
|
106
|
+
sframeKey = {
|
|
107
|
+
keyId: keyId,
|
|
108
|
+
key: key,
|
|
109
|
+
salt: salt,
|
|
110
|
+
};
|
|
111
|
+
this.keys.set(keyId, sframeKey);
|
|
112
|
+
console.log("\u2705 [SFrame] Key ".concat(keyId, " generated"));
|
|
113
|
+
return [2 /*return*/, sframeKey];
|
|
114
|
+
case 2:
|
|
115
|
+
error_2 = _a.sent();
|
|
116
|
+
console.error("\u274C [SFrame] Key generation failed:", error_2);
|
|
117
|
+
throw new Error("SFrame key generation failed: ".concat(error_2 instanceof Error ? error_2.message : String(error_2)));
|
|
118
|
+
case 3: return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Derive an SFrame key from MLS shared secret
|
|
125
|
+
* This allows SFrame to use keys derived from MLS for media encryption
|
|
126
|
+
* RFC 9605 Section 5.2: MLS-based key management
|
|
127
|
+
*/
|
|
128
|
+
SFrameManager.prototype.deriveKeyFromMLSSecret = function (mlsSecret_1, keyId_1) {
|
|
129
|
+
return __awaiter(this, arguments, void 0, function (mlsSecret, keyId, context) {
|
|
130
|
+
var secretLabel, saltLabel, baseKey, derivedSaltBits, salt, key, sframeKey, error_3;
|
|
131
|
+
if (context === void 0) { context = "SFrame"; }
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0:
|
|
135
|
+
_a.trys.push([0, 4, , 5]);
|
|
136
|
+
console.log("\uD83D\uDD17 [SFrame] Deriving key ".concat(keyId, " from MLS secret (RFC 9605 Section 5.2)..."));
|
|
137
|
+
secretLabel = new TextEncoder().encode("SFrame 1.0 Secret");
|
|
138
|
+
saltLabel = new TextEncoder().encode("SFrame 1.0 Salt");
|
|
139
|
+
return [4 /*yield*/, crypto.subtle.importKey("raw", mlsSecret, "HKDF", false, ["deriveKey", "deriveBits"])];
|
|
140
|
+
case 1:
|
|
141
|
+
baseKey = _a.sent();
|
|
142
|
+
return [4 /*yield*/, crypto.subtle.deriveBits({
|
|
143
|
+
name: "HKDF",
|
|
144
|
+
hash: "SHA-256",
|
|
145
|
+
salt: new Uint8Array(0), // Empty salt for salt derivation
|
|
146
|
+
info: saltLabel,
|
|
147
|
+
}, baseKey, 128)];
|
|
148
|
+
case 2:
|
|
149
|
+
derivedSaltBits = _a.sent();
|
|
150
|
+
salt = new Uint8Array(derivedSaltBits);
|
|
151
|
+
return [4 /*yield*/, crypto.subtle.deriveKey({
|
|
152
|
+
name: "HKDF",
|
|
153
|
+
hash: "SHA-256",
|
|
154
|
+
salt: new Uint8Array(0), // Empty salt for key derivation
|
|
155
|
+
info: secretLabel,
|
|
156
|
+
}, baseKey, {
|
|
157
|
+
name: "AES-GCM",
|
|
158
|
+
length: 128,
|
|
159
|
+
}, false, ["encrypt", "decrypt"])];
|
|
160
|
+
case 3:
|
|
161
|
+
key = _a.sent();
|
|
162
|
+
sframeKey = {
|
|
163
|
+
keyId: keyId,
|
|
164
|
+
key: key,
|
|
165
|
+
salt: salt,
|
|
166
|
+
};
|
|
167
|
+
this.keys.set(keyId, sframeKey);
|
|
168
|
+
console.log("\u2705 [SFrame] Key ".concat(keyId, " derived from MLS (RFC 9605 compliant)"));
|
|
169
|
+
return [2 /*return*/, sframeKey];
|
|
170
|
+
case 4:
|
|
171
|
+
error_3 = _a.sent();
|
|
172
|
+
console.error("\u274C [SFrame] Key derivation failed:", error_3);
|
|
173
|
+
throw new Error("SFrame key derivation failed: ".concat(error_3 instanceof Error ? error_3.message : String(error_3)));
|
|
174
|
+
case 5: return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Set a shared SFrame key (e.g., from another member)
|
|
181
|
+
*/
|
|
182
|
+
SFrameManager.prototype.setSharedKey = function (sframeKey) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
this.keys.set(sframeKey.keyId, sframeKey);
|
|
186
|
+
console.log("\u2705 [SFrame] Shared key ".concat(sframeKey.keyId, " set."));
|
|
187
|
+
return [2 /*return*/];
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Set the active encryption key
|
|
193
|
+
*/
|
|
194
|
+
SFrameManager.prototype.setActiveKey = function (keyId) {
|
|
195
|
+
if (!this.keys.has(keyId)) {
|
|
196
|
+
throw new Error("SFrame key ".concat(keyId, " not found"));
|
|
197
|
+
}
|
|
198
|
+
this.currentKeyId = keyId;
|
|
199
|
+
console.log("\uD83D\uDD04 [SFrame] Active key set to ".concat(keyId));
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Encrypt a media frame using SFrame
|
|
203
|
+
*/
|
|
204
|
+
SFrameManager.prototype.encryptFrame = function (frameData) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
var sframeKey, counterBytes, counterView, header, iv, i, ciphertext, encrypted, error_4;
|
|
207
|
+
return __generator(this, function (_a) {
|
|
208
|
+
switch (_a.label) {
|
|
209
|
+
case 0:
|
|
210
|
+
this.ensureInitialized();
|
|
211
|
+
_a.label = 1;
|
|
212
|
+
case 1:
|
|
213
|
+
_a.trys.push([1, 3, , 4]);
|
|
214
|
+
sframeKey = this.keys.get(this.currentKeyId);
|
|
215
|
+
if (!sframeKey) {
|
|
216
|
+
throw new Error("SFrame key ".concat(this.currentKeyId, " not found"));
|
|
217
|
+
}
|
|
218
|
+
counterBytes = new Uint8Array(12);
|
|
219
|
+
counterView = new DataView(counterBytes.buffer);
|
|
220
|
+
// Store frame counter in last 8 bytes (big-endian uint64-like)
|
|
221
|
+
counterView.setUint32(4, Math.floor(this.frameCounter / 0x100000000), false);
|
|
222
|
+
counterView.setUint32(8, this.frameCounter & 0xffffffff, false);
|
|
223
|
+
header = new Uint8Array(5);
|
|
224
|
+
header[0] = this.currentKeyId;
|
|
225
|
+
new DataView(header.buffer).setUint32(1, this.frameCounter, false);
|
|
226
|
+
iv = new Uint8Array(12);
|
|
227
|
+
for (i = 0; i < 12; i++) {
|
|
228
|
+
iv[i] = sframeKey.salt[i] ^ counterBytes[i];
|
|
229
|
+
}
|
|
230
|
+
return [4 /*yield*/, crypto.subtle.encrypt({
|
|
231
|
+
name: "AES-GCM",
|
|
232
|
+
iv: iv,
|
|
233
|
+
additionalData: header, // RFC 9605: Header included in AAD
|
|
234
|
+
tagLength: 128, // 128-bit authentication tag
|
|
235
|
+
}, sframeKey.key, frameData)];
|
|
236
|
+
case 2:
|
|
237
|
+
ciphertext = _a.sent();
|
|
238
|
+
encrypted = new Uint8Array(header.length + ciphertext.byteLength);
|
|
239
|
+
encrypted.set(header, 0);
|
|
240
|
+
encrypted.set(new Uint8Array(ciphertext), header.length);
|
|
241
|
+
// Increment frame counter
|
|
242
|
+
this.frameCounter++;
|
|
243
|
+
return [2 /*return*/, encrypted];
|
|
244
|
+
case 3:
|
|
245
|
+
error_4 = _a.sent();
|
|
246
|
+
console.error("❌ [SFrame] Frame encryption failed:", error_4);
|
|
247
|
+
throw new Error("SFrame encryption failed: ".concat(error_4 instanceof Error ? error_4.message : String(error_4)));
|
|
248
|
+
case 4: return [2 /*return*/];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Decrypt a media frame using SFrame
|
|
255
|
+
*/
|
|
256
|
+
SFrameManager.prototype.decryptFrame = function (encryptedFrame) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var header, keyId, frameCount, sframeKey, counterBytes, counterView, iv, i, ciphertext, plaintext, error_5;
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
this.ensureInitialized();
|
|
263
|
+
_a.label = 1;
|
|
264
|
+
case 1:
|
|
265
|
+
_a.trys.push([1, 3, , 4]);
|
|
266
|
+
header = encryptedFrame.slice(0, 5);
|
|
267
|
+
keyId = header[0];
|
|
268
|
+
frameCount = new DataView(header.buffer, header.byteOffset).getUint32(1, false);
|
|
269
|
+
sframeKey = this.keys.get(keyId);
|
|
270
|
+
if (!sframeKey) {
|
|
271
|
+
throw new Error("SFrame key ".concat(keyId, " not found"));
|
|
272
|
+
}
|
|
273
|
+
counterBytes = new Uint8Array(12);
|
|
274
|
+
counterView = new DataView(counterBytes.buffer);
|
|
275
|
+
counterView.setUint32(4, Math.floor(frameCount / 0x100000000), false);
|
|
276
|
+
counterView.setUint32(8, frameCount & 0xffffffff, false);
|
|
277
|
+
iv = new Uint8Array(12);
|
|
278
|
+
for (i = 0; i < 12; i++) {
|
|
279
|
+
iv[i] = sframeKey.salt[i] ^ counterBytes[i];
|
|
280
|
+
}
|
|
281
|
+
ciphertext = encryptedFrame.slice(header.length);
|
|
282
|
+
return [4 /*yield*/, crypto.subtle.decrypt({
|
|
283
|
+
name: "AES-GCM",
|
|
284
|
+
iv: iv,
|
|
285
|
+
additionalData: header, // RFC 9605: Header included in AAD
|
|
286
|
+
tagLength: 128,
|
|
287
|
+
}, sframeKey.key, ciphertext)];
|
|
288
|
+
case 2:
|
|
289
|
+
plaintext = _a.sent();
|
|
290
|
+
return [2 /*return*/, plaintext];
|
|
291
|
+
case 3:
|
|
292
|
+
error_5 = _a.sent();
|
|
293
|
+
console.error("❌ [SFrame] Frame decryption failed:", error_5);
|
|
294
|
+
throw new Error("SFrame decryption failed: ".concat(error_5 instanceof Error ? error_5.message : String(error_5)));
|
|
295
|
+
case 4: return [2 /*return*/];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Encrypt transform function for Insertable Streams
|
|
302
|
+
* Use this with RTCRtpSender.createEncodedStreams()
|
|
303
|
+
*/
|
|
304
|
+
SFrameManager.prototype.createEncryptTransform = function () {
|
|
305
|
+
var manager = this;
|
|
306
|
+
return new TransformStream({
|
|
307
|
+
transform: function (encodedFrame, controller) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
309
|
+
var frameData, encrypted, error_6;
|
|
310
|
+
return __generator(this, function (_a) {
|
|
311
|
+
switch (_a.label) {
|
|
312
|
+
case 0:
|
|
313
|
+
_a.trys.push([0, 2, , 3]);
|
|
314
|
+
frameData = encodedFrame.data;
|
|
315
|
+
return [4 /*yield*/, manager.encryptFrame(frameData)];
|
|
316
|
+
case 1:
|
|
317
|
+
encrypted = _a.sent();
|
|
318
|
+
// Create new encoded frame with encrypted data
|
|
319
|
+
encodedFrame.data = encrypted.buffer;
|
|
320
|
+
// Forward the encrypted frame
|
|
321
|
+
controller.enqueue(encodedFrame);
|
|
322
|
+
return [3 /*break*/, 3];
|
|
323
|
+
case 2:
|
|
324
|
+
error_6 = _a.sent();
|
|
325
|
+
console.error("[SFrame] Encrypt transform error:", error_6);
|
|
326
|
+
// Forward unencrypted frame on error (fallback)
|
|
327
|
+
controller.enqueue(encodedFrame);
|
|
328
|
+
return [3 /*break*/, 3];
|
|
329
|
+
case 3: return [2 /*return*/];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Decrypt transform function for Insertable Streams
|
|
338
|
+
* Use this with RTCRtpReceiver.createEncodedStreams()
|
|
339
|
+
*/
|
|
340
|
+
SFrameManager.prototype.createDecryptTransform = function () {
|
|
341
|
+
var manager = this;
|
|
342
|
+
return new TransformStream({
|
|
343
|
+
transform: function (encodedFrame, controller) {
|
|
344
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
345
|
+
var encryptedData, decrypted, error_7;
|
|
346
|
+
return __generator(this, function (_a) {
|
|
347
|
+
switch (_a.label) {
|
|
348
|
+
case 0:
|
|
349
|
+
_a.trys.push([0, 2, , 3]);
|
|
350
|
+
encryptedData = new Uint8Array(encodedFrame.data);
|
|
351
|
+
return [4 /*yield*/, manager.decryptFrame(encryptedData)];
|
|
352
|
+
case 1:
|
|
353
|
+
decrypted = _a.sent();
|
|
354
|
+
// Create new encoded frame with decrypted data
|
|
355
|
+
encodedFrame.data = decrypted;
|
|
356
|
+
// Forward the decrypted frame
|
|
357
|
+
controller.enqueue(encodedFrame);
|
|
358
|
+
return [3 /*break*/, 3];
|
|
359
|
+
case 2:
|
|
360
|
+
error_7 = _a.sent();
|
|
361
|
+
console.error("[SFrame] Decrypt transform error:", error_7);
|
|
362
|
+
return [3 /*break*/, 3];
|
|
363
|
+
case 3: return [2 /*return*/];
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Rotate encryption keys
|
|
372
|
+
* RFC 9605: Frame counter should be reset on key rotation to prevent exhaustion
|
|
373
|
+
*/
|
|
374
|
+
SFrameManager.prototype.rotateKey = function () {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
376
|
+
var newKeyId, error_8;
|
|
377
|
+
return __generator(this, function (_a) {
|
|
378
|
+
switch (_a.label) {
|
|
379
|
+
case 0:
|
|
380
|
+
_a.trys.push([0, 2, , 3]);
|
|
381
|
+
newKeyId = this.currentKeyId + 1;
|
|
382
|
+
console.log("\uD83D\uDD04 [SFrame] Rotating to key ".concat(newKeyId, "..."));
|
|
383
|
+
return [4 /*yield*/, this.generateKey(newKeyId)];
|
|
384
|
+
case 1:
|
|
385
|
+
_a.sent();
|
|
386
|
+
this.setActiveKey(newKeyId);
|
|
387
|
+
// RFC 9605: Reset frame counter on key rotation
|
|
388
|
+
this.resetFrameCounter();
|
|
389
|
+
console.log("\uD83D\uDD04 [SFrame] Frame counter reset to 0 for new key");
|
|
390
|
+
console.log("\u2705 [SFrame] Key rotated to ".concat(newKeyId));
|
|
391
|
+
return [2 /*return*/, newKeyId];
|
|
392
|
+
case 2:
|
|
393
|
+
error_8 = _a.sent();
|
|
394
|
+
console.error("❌ [SFrame] Key rotation failed:", error_8);
|
|
395
|
+
throw new Error("SFrame key rotation failed: ".concat(error_8 instanceof Error ? error_8.message : String(error_8)));
|
|
396
|
+
case 3: return [2 /*return*/];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Get current key ID
|
|
403
|
+
*/
|
|
404
|
+
SFrameManager.prototype.getCurrentKeyId = function () {
|
|
405
|
+
return this.currentKeyId;
|
|
406
|
+
};
|
|
407
|
+
/**
|
|
408
|
+
* Get frame counter (for debugging)
|
|
409
|
+
*/
|
|
410
|
+
SFrameManager.prototype.getFrameCounter = function () {
|
|
411
|
+
return this.frameCounter;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* Reset frame counter (use when rotating keys)
|
|
415
|
+
*/
|
|
416
|
+
SFrameManager.prototype.resetFrameCounter = function () {
|
|
417
|
+
this.frameCounter = 0;
|
|
418
|
+
console.log("🔄 [SFrame] Frame counter reset");
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Remove old keys to prevent memory bloat
|
|
422
|
+
*/
|
|
423
|
+
SFrameManager.prototype.cleanupOldKeys = function (keepLast) {
|
|
424
|
+
var _this = this;
|
|
425
|
+
if (keepLast === void 0) { keepLast = 2; }
|
|
426
|
+
var keyIds = Array.from(this.keys.keys()).sort(function (a, b) { return b - a; });
|
|
427
|
+
if (keyIds.length > keepLast) {
|
|
428
|
+
var toDelete = keyIds.slice(keepLast);
|
|
429
|
+
toDelete.forEach(function (keyId) {
|
|
430
|
+
_this.keys.delete(keyId);
|
|
431
|
+
console.log("\uD83E\uDDF9 [SFrame] Deleted old key ".concat(keyId));
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Get statistics
|
|
437
|
+
*/
|
|
438
|
+
SFrameManager.prototype.getStats = function () {
|
|
439
|
+
return {
|
|
440
|
+
keyCount: this.keys.size,
|
|
441
|
+
currentKeyId: this.currentKeyId,
|
|
442
|
+
frameCounter: this.frameCounter,
|
|
443
|
+
initialized: this.initialized,
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* Clean up resources
|
|
448
|
+
*/
|
|
449
|
+
SFrameManager.prototype.destroy = function () {
|
|
450
|
+
this.keys.clear();
|
|
451
|
+
this.initialized = false;
|
|
452
|
+
this.frameCounter = 0;
|
|
453
|
+
console.log("✅ [SFrame] Manager destroyed");
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Ensure the manager is initialized
|
|
457
|
+
*/
|
|
458
|
+
SFrameManager.prototype.ensureInitialized = function () {
|
|
459
|
+
if (!this.initialized) {
|
|
460
|
+
throw new Error("SFrame Manager not initialized. Call initialize() first.");
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
return SFrameManager;
|
|
464
|
+
}());
|
|
465
|
+
export { SFrameManager };
|
|
466
|
+
export default SFrameManager;
|