shogun-core 6.2.4 → 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 +138979 -146789
- 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 -392
- 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,165 @@
|
|
|
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
|
+
import { arrayBufferToBase64, base64ToArrayBuffer } from "./hashing.js";
|
|
38
|
+
// Symmetric Key Generation and Encryption/Decryption Methods
|
|
39
|
+
export var generateSymmetricKey = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
40
|
+
var key, keyJWK;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0: return [4 /*yield*/, crypto.subtle.generateKey({
|
|
44
|
+
name: "AES-GCM",
|
|
45
|
+
length: 256, // can be 128, 192, or 256
|
|
46
|
+
}, true, // whether the key is extractable
|
|
47
|
+
["encrypt", "decrypt"])];
|
|
48
|
+
case 1:
|
|
49
|
+
key = _a.sent();
|
|
50
|
+
return [4 /*yield*/, crypto.subtle.exportKey("jwk", key)];
|
|
51
|
+
case 2:
|
|
52
|
+
keyJWK = _a.sent();
|
|
53
|
+
return [2 /*return*/, keyJWK];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}); };
|
|
57
|
+
export var deserializeSymmetricKey = function (key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
58
|
+
var jwkKey, deSerializedSymmetricKey, error_1;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
_a.trys.push([0, 2, , 3]);
|
|
63
|
+
jwkKey = typeof key === "string" ? JSON.parse(key) : key;
|
|
64
|
+
// Validate that required JWK properties exist for symmetric keys
|
|
65
|
+
if (!jwkKey.kty) {
|
|
66
|
+
throw new Error('Invalid JWK: missing "kty" property');
|
|
67
|
+
}
|
|
68
|
+
// Ensure the key type is correct for symmetric keys
|
|
69
|
+
if (jwkKey.kty !== "oct") {
|
|
70
|
+
jwkKey.kty = "oct";
|
|
71
|
+
}
|
|
72
|
+
return [4 /*yield*/, crypto.subtle.importKey("jwk", jwkKey, {
|
|
73
|
+
name: "AES-GCM",
|
|
74
|
+
}, true, ["encrypt", "decrypt"])];
|
|
75
|
+
case 1:
|
|
76
|
+
deSerializedSymmetricKey = _a.sent();
|
|
77
|
+
return [2 /*return*/, deSerializedSymmetricKey];
|
|
78
|
+
case 2:
|
|
79
|
+
error_1 = _a.sent();
|
|
80
|
+
console.error("Error deserializing symmetric key:", error_1);
|
|
81
|
+
throw error_1;
|
|
82
|
+
case 3: return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); };
|
|
86
|
+
export var encryptWithSymmetricKey = function (message, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
var encodedMessage, iv, encrypted;
|
|
88
|
+
return __generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
encodedMessage = new TextEncoder().encode(message);
|
|
92
|
+
iv = crypto.getRandomValues(new Uint8Array(12));
|
|
93
|
+
return [4 /*yield*/, crypto.subtle.encrypt({
|
|
94
|
+
name: "AES-GCM",
|
|
95
|
+
iv: iv,
|
|
96
|
+
}, key, encodedMessage)];
|
|
97
|
+
case 1:
|
|
98
|
+
encrypted = _a.sent();
|
|
99
|
+
return [2 /*return*/, {
|
|
100
|
+
ciphertext: arrayBufferToBase64(encrypted),
|
|
101
|
+
iv: arrayBufferToBase64(iv.buffer),
|
|
102
|
+
}];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}); };
|
|
106
|
+
export var decryptWithSymmetricKey = function (encryptedData, key) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
+
var ciphertext, iv, buffer, ivBuffer, decrypted, message, error_2;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
switch (_a.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
ciphertext = encryptedData.ciphertext, iv = encryptedData.iv;
|
|
112
|
+
buffer = base64ToArrayBuffer(ciphertext);
|
|
113
|
+
ivBuffer = base64ToArrayBuffer(iv);
|
|
114
|
+
_a.label = 1;
|
|
115
|
+
case 1:
|
|
116
|
+
_a.trys.push([1, 3, , 4]);
|
|
117
|
+
return [4 /*yield*/, crypto.subtle.decrypt({
|
|
118
|
+
name: "AES-GCM",
|
|
119
|
+
iv: ivBuffer,
|
|
120
|
+
}, key, buffer)];
|
|
121
|
+
case 2:
|
|
122
|
+
decrypted = _a.sent();
|
|
123
|
+
message = new TextDecoder().decode(decrypted);
|
|
124
|
+
return [2 /*return*/, message];
|
|
125
|
+
case 3:
|
|
126
|
+
error_2 = _a.sent();
|
|
127
|
+
throw new Error("Unable to decrypt message. Incorrect key.");
|
|
128
|
+
case 4: return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); };
|
|
132
|
+
// Password-based key derivation
|
|
133
|
+
export var deriveKeyFromPassword = function (password, salt) { return __awaiter(void 0, void 0, void 0, function () {
|
|
134
|
+
var encoder, actualSalt, _a, passwordKey, derivedKey;
|
|
135
|
+
return __generator(this, function (_b) {
|
|
136
|
+
switch (_b.label) {
|
|
137
|
+
case 0:
|
|
138
|
+
encoder = new TextEncoder();
|
|
139
|
+
_a = salt;
|
|
140
|
+
if (_a) return [3 /*break*/, 2];
|
|
141
|
+
return [4 /*yield*/, crypto.subtle.digest("SHA-256", encoder.encode(password))];
|
|
142
|
+
case 1:
|
|
143
|
+
_a = (_b.sent());
|
|
144
|
+
_b.label = 2;
|
|
145
|
+
case 2:
|
|
146
|
+
actualSalt = _a;
|
|
147
|
+
return [4 /*yield*/, crypto.subtle.importKey("raw", encoder.encode(password), "PBKDF2", false, ["deriveKey"])];
|
|
148
|
+
case 3:
|
|
149
|
+
passwordKey = _b.sent();
|
|
150
|
+
return [4 /*yield*/, crypto.subtle.deriveKey({
|
|
151
|
+
name: "PBKDF2",
|
|
152
|
+
salt: actualSalt,
|
|
153
|
+
iterations: 100000, // Strong iteration count
|
|
154
|
+
hash: "SHA-256",
|
|
155
|
+
}, passwordKey, {
|
|
156
|
+
name: "AES-GCM",
|
|
157
|
+
length: 256,
|
|
158
|
+
}, false, // Not extractable for security
|
|
159
|
+
["encrypt", "decrypt"])];
|
|
160
|
+
case 4:
|
|
161
|
+
derivedKey = _b.sent();
|
|
162
|
+
return [2 /*return*/, { key: derivedKey, salt: actualSalt }];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); };
|
|
@@ -0,0 +1,220 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
38
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
+
if (!m) return o;
|
|
40
|
+
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
try {
|
|
42
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
+
}
|
|
44
|
+
catch (error) { e = { error: error }; }
|
|
45
|
+
finally {
|
|
46
|
+
try {
|
|
47
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e) throw e.error; }
|
|
50
|
+
}
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
+
if (ar || !(i in from)) {
|
|
56
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
+
ar[i] = from[i];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
+
};
|
|
62
|
+
// Common utility functions for crypto operations
|
|
63
|
+
export var validatePassword = function (password) {
|
|
64
|
+
// Basic password validation
|
|
65
|
+
return password.length >= 8;
|
|
66
|
+
};
|
|
67
|
+
export var generateSecurePassword = function (length) {
|
|
68
|
+
if (length === void 0) { length = 16; }
|
|
69
|
+
var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
|
|
70
|
+
var randomValues = crypto.getRandomValues(new Uint8Array(length));
|
|
71
|
+
var password = "";
|
|
72
|
+
for (var i = 0; i < length; i++) {
|
|
73
|
+
password += charset[randomValues[i] % charset.length];
|
|
74
|
+
}
|
|
75
|
+
return password;
|
|
76
|
+
};
|
|
77
|
+
export var measurePerformance = function (operation, operationName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
+
var start, result, end, duration;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
start = performance.now();
|
|
83
|
+
return [4 /*yield*/, operation()];
|
|
84
|
+
case 1:
|
|
85
|
+
result = _a.sent();
|
|
86
|
+
end = performance.now();
|
|
87
|
+
duration = end - start;
|
|
88
|
+
console.log("\u23F1\uFE0F ".concat(operationName, " took ").concat(duration.toFixed(2), "ms"));
|
|
89
|
+
return [2 /*return*/, { result: result, duration: duration }];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}); };
|
|
93
|
+
export var formatBytes = function (bytes) {
|
|
94
|
+
if (bytes === 0)
|
|
95
|
+
return "0 Bytes";
|
|
96
|
+
var k = 1024;
|
|
97
|
+
var sizes = ["Bytes", "KB", "MB", "GB"];
|
|
98
|
+
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
99
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
|
100
|
+
};
|
|
101
|
+
export var formatDuration = function (ms) {
|
|
102
|
+
if (ms < 1000)
|
|
103
|
+
return "".concat(ms.toFixed(2), "ms");
|
|
104
|
+
if (ms < 60000)
|
|
105
|
+
return "".concat((ms / 1000).toFixed(2), "s");
|
|
106
|
+
return "".concat((ms / 60000).toFixed(2), "m");
|
|
107
|
+
};
|
|
108
|
+
export var createProgressCallback = function (onProgress, total) {
|
|
109
|
+
var current = 0;
|
|
110
|
+
return {
|
|
111
|
+
increment: function (amount) {
|
|
112
|
+
if (amount === void 0) { amount = 1; }
|
|
113
|
+
current += amount;
|
|
114
|
+
var progress = Math.min((current / total) * 100, 100);
|
|
115
|
+
onProgress(progress);
|
|
116
|
+
},
|
|
117
|
+
setProgress: function (progress) {
|
|
118
|
+
current = (progress / 100) * total;
|
|
119
|
+
onProgress(progress);
|
|
120
|
+
},
|
|
121
|
+
complete: function () {
|
|
122
|
+
current = total;
|
|
123
|
+
onProgress(100);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
export var sanitizeFileName = function (fileName) {
|
|
128
|
+
// Remove or replace invalid characters
|
|
129
|
+
return fileName.replace(/[<>:"/\\|?*]/g, "_");
|
|
130
|
+
};
|
|
131
|
+
export var getFileExtension = function (fileName) {
|
|
132
|
+
var lastDot = fileName.lastIndexOf(".");
|
|
133
|
+
return lastDot !== -1 ? fileName.substring(lastDot + 1).toLowerCase() : "";
|
|
134
|
+
};
|
|
135
|
+
export var isTextFile = function (fileName) {
|
|
136
|
+
var textExtensions = [
|
|
137
|
+
"txt",
|
|
138
|
+
"md",
|
|
139
|
+
"json",
|
|
140
|
+
"js",
|
|
141
|
+
"ts",
|
|
142
|
+
"html",
|
|
143
|
+
"css",
|
|
144
|
+
"xml",
|
|
145
|
+
"csv",
|
|
146
|
+
];
|
|
147
|
+
var extension = getFileExtension(fileName);
|
|
148
|
+
return textExtensions.includes(extension);
|
|
149
|
+
};
|
|
150
|
+
export var createFileHash = function (file) { return __awaiter(void 0, void 0, void 0, function () {
|
|
151
|
+
var buffer, hashBuffer, hashArray;
|
|
152
|
+
return __generator(this, function (_a) {
|
|
153
|
+
switch (_a.label) {
|
|
154
|
+
case 0: return [4 /*yield*/, file.arrayBuffer()];
|
|
155
|
+
case 1:
|
|
156
|
+
buffer = _a.sent();
|
|
157
|
+
return [4 /*yield*/, crypto.subtle.digest("SHA-256", buffer)];
|
|
158
|
+
case 2:
|
|
159
|
+
hashBuffer = _a.sent();
|
|
160
|
+
hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
161
|
+
return [2 /*return*/, hashArray.map(function (b) { return b.toString(16).padStart(2, "0"); }).join("")];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}); };
|
|
165
|
+
export var compareFiles = function (file1, file2) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var hash1, hash2;
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
if (file1.size !== file2.size)
|
|
171
|
+
return [2 /*return*/, false];
|
|
172
|
+
return [4 /*yield*/, createFileHash(file1)];
|
|
173
|
+
case 1:
|
|
174
|
+
hash1 = _a.sent();
|
|
175
|
+
return [4 /*yield*/, createFileHash(file2)];
|
|
176
|
+
case 2:
|
|
177
|
+
hash2 = _a.sent();
|
|
178
|
+
return [2 /*return*/, hash1 === hash2];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}); };
|
|
182
|
+
export var createBackup = function (data) {
|
|
183
|
+
return JSON.stringify({
|
|
184
|
+
data: data,
|
|
185
|
+
timestamp: new Date().toISOString(),
|
|
186
|
+
version: "1.0",
|
|
187
|
+
}, null, 2);
|
|
188
|
+
};
|
|
189
|
+
export var restoreBackup = function (backupString) {
|
|
190
|
+
var backup = JSON.parse(backupString);
|
|
191
|
+
if (!backup.timestamp || !backup.data) {
|
|
192
|
+
throw new Error("Invalid backup format");
|
|
193
|
+
}
|
|
194
|
+
return backup.data;
|
|
195
|
+
};
|
|
196
|
+
export var debounce = function (func, wait) {
|
|
197
|
+
var timeout;
|
|
198
|
+
return function () {
|
|
199
|
+
var args = [];
|
|
200
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
201
|
+
args[_i] = arguments[_i];
|
|
202
|
+
}
|
|
203
|
+
clearTimeout(timeout);
|
|
204
|
+
timeout = setTimeout(function () { return func.apply(void 0, __spreadArray([], __read(args), false)); }, wait);
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
export var throttle = function (func, limit) {
|
|
208
|
+
var inThrottle;
|
|
209
|
+
return function () {
|
|
210
|
+
var args = [];
|
|
211
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
212
|
+
args[_i] = arguments[_i];
|
|
213
|
+
}
|
|
214
|
+
if (!inThrottle) {
|
|
215
|
+
func.apply(void 0, __spreadArray([], __read(args), false));
|
|
216
|
+
inThrottle = true;
|
|
217
|
+
setTimeout(function () { return (inThrottle = false); }, limit);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
};
|