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,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Esempio di utilizzo del CryptoIdentityManager
|
|
3
|
+
* Mostra come generare le identità crypto
|
|
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 SEA as side-effect to load it globally
|
|
42
|
+
import "gun/sea";
|
|
43
|
+
import "gun/lib/then";
|
|
44
|
+
import "gun/axe";
|
|
45
|
+
// Ensure Gun.SEA is available globally
|
|
46
|
+
// In Node.js, SEA should attach to Gun.SEA or globalThis.SEA
|
|
47
|
+
if (typeof window === "undefined") {
|
|
48
|
+
// Node.js environment
|
|
49
|
+
var GunModule = require("gun");
|
|
50
|
+
if (GunModule && GunModule.SEA) {
|
|
51
|
+
globalThis.Gun = GunModule;
|
|
52
|
+
globalThis.SEA = GunModule.SEA;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Suppress expected Gun.js SEA verification errors globally
|
|
56
|
+
// These errors are normal when verifying non-existent or corrupted data
|
|
57
|
+
var originalLog = console.log;
|
|
58
|
+
var originalError = console.error;
|
|
59
|
+
var errorSuppressionActive = false;
|
|
60
|
+
var suppressedLog = function () {
|
|
61
|
+
var args = [];
|
|
62
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
63
|
+
args[_i] = arguments[_i];
|
|
64
|
+
}
|
|
65
|
+
if (!errorSuppressionActive) {
|
|
66
|
+
originalLog.apply(console, args);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var message = args.join(" ");
|
|
70
|
+
// Suppress expected SEA verification errors
|
|
71
|
+
if (message.includes("Signature did not match") ||
|
|
72
|
+
message.includes("base64Text") ||
|
|
73
|
+
message.includes("Could not decrypt") ||
|
|
74
|
+
message.includes("Argument 'base64Text' is not Base64 encoded")) {
|
|
75
|
+
return; // Suppress these expected errors
|
|
76
|
+
}
|
|
77
|
+
originalLog.apply(console, args);
|
|
78
|
+
};
|
|
79
|
+
var suppressedError = function () {
|
|
80
|
+
var args = [];
|
|
81
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
|
+
args[_i] = arguments[_i];
|
|
83
|
+
}
|
|
84
|
+
if (!errorSuppressionActive) {
|
|
85
|
+
originalError.apply(console, args);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
var message = args.join(" ");
|
|
89
|
+
if (message.includes("Signature did not match") ||
|
|
90
|
+
message.includes("base64Text") ||
|
|
91
|
+
message.includes("Could not decrypt") ||
|
|
92
|
+
message.includes("Argument 'base64Text' is not Base64 encoded")) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
originalError.apply(console, args);
|
|
96
|
+
};
|
|
97
|
+
// Enable error suppression
|
|
98
|
+
errorSuppressionActive = true;
|
|
99
|
+
console.log = suppressedLog;
|
|
100
|
+
console.error = suppressedError;
|
|
101
|
+
import { CryptoIdentityManager } from "../index.js";
|
|
102
|
+
// Esempio base di generazione identità
|
|
103
|
+
function basicIdentityExample() {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var SEA, exampleUser, examplePassword, seaPair, cryptoManager, generateResult, identities, identitiesJson;
|
|
106
|
+
var _a, _b;
|
|
107
|
+
return __generator(this, function (_c) {
|
|
108
|
+
switch (_c.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
console.log("🚀 Avvio esempio CryptoIdentityManager");
|
|
111
|
+
if (!(!globalThis.SEA && !((_a = globalThis.Gun) === null || _a === void 0 ? void 0 : _a.SEA))) return [3 /*break*/, 2];
|
|
112
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
|
|
113
|
+
case 1:
|
|
114
|
+
_c.sent();
|
|
115
|
+
_c.label = 2;
|
|
116
|
+
case 2:
|
|
117
|
+
SEA = globalThis.SEA || ((_b = globalThis.Gun) === null || _b === void 0 ? void 0 : _b.SEA);
|
|
118
|
+
if (!SEA) {
|
|
119
|
+
console.error("❌ SEA non disponibile. Assicurati che gun/sea sia importato.");
|
|
120
|
+
return [2 /*return*/];
|
|
121
|
+
}
|
|
122
|
+
console.log("✅ SEA disponibile");
|
|
123
|
+
exampleUser = "example_user_" + Date.now();
|
|
124
|
+
examplePassword = "example_password";
|
|
125
|
+
console.log("\uD83D\uDD10 Generazione SEA pair di esempio per: ".concat(exampleUser));
|
|
126
|
+
return [4 /*yield*/, SEA.pair()];
|
|
127
|
+
case 3:
|
|
128
|
+
seaPair = _c.sent();
|
|
129
|
+
if (!seaPair) {
|
|
130
|
+
console.error("❌ Impossibile generare SEA pair di esempio");
|
|
131
|
+
return [2 /*return*/];
|
|
132
|
+
}
|
|
133
|
+
console.log("✅ SEA pair generato");
|
|
134
|
+
cryptoManager = new CryptoIdentityManager();
|
|
135
|
+
// Genera le identità crypto
|
|
136
|
+
console.log("🔐 Generazione delle identità crypto...");
|
|
137
|
+
return [4 /*yield*/, cryptoManager.generateAllIdentities(exampleUser, seaPair)];
|
|
138
|
+
case 4:
|
|
139
|
+
generateResult = _c.sent();
|
|
140
|
+
if (generateResult.success && generateResult.identities) {
|
|
141
|
+
identities = generateResult.identities;
|
|
142
|
+
console.log("✅ Identità crypto generate con successo!");
|
|
143
|
+
console.log("🔐 Identità crypto generate:");
|
|
144
|
+
console.log("- RSA Key Pair:", !!identities.rsa);
|
|
145
|
+
console.log("- AES Symmetric Key:", !!identities.aes);
|
|
146
|
+
console.log("- Signal Protocol Identity:", !!identities.signal);
|
|
147
|
+
console.log("- PGP Key Pair:", !!identities.pgp);
|
|
148
|
+
console.log("- MLS Group:", !!identities.mls);
|
|
149
|
+
console.log("- SFrame Key:", !!identities.sframe);
|
|
150
|
+
console.log("- Created At:", new Date(identities.createdAt).toISOString());
|
|
151
|
+
console.log("- Version:", identities.version);
|
|
152
|
+
console.log("\nℹ️ Nota: Le identità generate dovranno essere salvate lato frontend se necessario.");
|
|
153
|
+
identitiesJson = JSON.stringify(identities);
|
|
154
|
+
console.log("\n\uD83D\uDCE6 Identit\u00E0 serializzate (".concat(identitiesJson.length, " caratteri)"));
|
|
155
|
+
console.log("💡 Puoi criptare e salvare questa stringa usando SEA.encrypt() lato frontend");
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.warn("⚠️ Impossibile generare le identità crypto:", generateResult.error);
|
|
159
|
+
}
|
|
160
|
+
console.log("\n🎉 Esempio completato!");
|
|
161
|
+
// Restore original console methods at the end
|
|
162
|
+
errorSuppressionActive = false;
|
|
163
|
+
console.log = originalLog;
|
|
164
|
+
console.error = originalError;
|
|
165
|
+
return [2 /*return*/];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Esempio di rigenerazione delle identità
|
|
171
|
+
function regenerateIdentityExample() {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
var SEA, exampleUser, seaPair, cryptoManager, firstResult, secondResult;
|
|
174
|
+
var _a;
|
|
175
|
+
return __generator(this, function (_b) {
|
|
176
|
+
switch (_b.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
console.log("\n🔄 Esempio di rigenerazione identità");
|
|
179
|
+
SEA = globalThis.SEA || ((_a = globalThis.Gun) === null || _a === void 0 ? void 0 : _a.SEA);
|
|
180
|
+
if (!SEA) {
|
|
181
|
+
console.error("❌ SEA non disponibile");
|
|
182
|
+
return [2 /*return*/];
|
|
183
|
+
}
|
|
184
|
+
exampleUser = "example_user_regenerate";
|
|
185
|
+
return [4 /*yield*/, SEA.pair()];
|
|
186
|
+
case 1:
|
|
187
|
+
seaPair = _b.sent();
|
|
188
|
+
cryptoManager = new CryptoIdentityManager();
|
|
189
|
+
console.log("🔐 Prima generazione...");
|
|
190
|
+
return [4 /*yield*/, cryptoManager.generateAllIdentities(exampleUser, seaPair)];
|
|
191
|
+
case 2:
|
|
192
|
+
firstResult = _b.sent();
|
|
193
|
+
if (firstResult.success && firstResult.identities) {
|
|
194
|
+
console.log("✅ Prima generazione completata");
|
|
195
|
+
console.log("- RSA:", !!firstResult.identities.rsa);
|
|
196
|
+
console.log("- AES:", !!firstResult.identities.aes);
|
|
197
|
+
}
|
|
198
|
+
console.log("\n🔐 Seconda generazione (nuove identità)...");
|
|
199
|
+
return [4 /*yield*/, cryptoManager.generateAllIdentities(exampleUser, seaPair)];
|
|
200
|
+
case 3:
|
|
201
|
+
secondResult = _b.sent();
|
|
202
|
+
if (secondResult.success && secondResult.identities) {
|
|
203
|
+
console.log("✅ Seconda generazione completata");
|
|
204
|
+
console.log("- RSA:", !!secondResult.identities.rsa);
|
|
205
|
+
console.log("- AES:", !!secondResult.identities.aes);
|
|
206
|
+
console.log("ℹ️ Nota: Ogni generazione crea nuove identità uniche");
|
|
207
|
+
}
|
|
208
|
+
// Restore original console methods at the end
|
|
209
|
+
errorSuppressionActive = false;
|
|
210
|
+
console.log = originalLog;
|
|
211
|
+
console.error = originalError;
|
|
212
|
+
return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// Esempio usando setupCryptoIdentities (wrapper)
|
|
218
|
+
function setupIdentityExample() {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
+
var SEA, exampleUser, seaPair, cryptoManager, result;
|
|
221
|
+
var _a;
|
|
222
|
+
return __generator(this, function (_b) {
|
|
223
|
+
switch (_b.label) {
|
|
224
|
+
case 0:
|
|
225
|
+
console.log("\n🔧 Esempio usando setupCryptoIdentities");
|
|
226
|
+
SEA = globalThis.SEA || ((_a = globalThis.Gun) === null || _a === void 0 ? void 0 : _a.SEA);
|
|
227
|
+
if (!SEA) {
|
|
228
|
+
console.error("❌ SEA non disponibile");
|
|
229
|
+
return [2 /*return*/];
|
|
230
|
+
}
|
|
231
|
+
exampleUser = "example_user_setup";
|
|
232
|
+
return [4 /*yield*/, SEA.pair()];
|
|
233
|
+
case 1:
|
|
234
|
+
seaPair = _b.sent();
|
|
235
|
+
cryptoManager = new CryptoIdentityManager();
|
|
236
|
+
console.log("🔐 Usando setupCryptoIdentities (wrapper)...");
|
|
237
|
+
return [4 /*yield*/, cryptoManager.setupCryptoIdentities(exampleUser, seaPair, false)];
|
|
238
|
+
case 2:
|
|
239
|
+
result = _b.sent();
|
|
240
|
+
if (result.success && result.identities) {
|
|
241
|
+
console.log("✅ Identità generate usando setupCryptoIdentities");
|
|
242
|
+
console.log("- RSA:", !!result.identities.rsa);
|
|
243
|
+
console.log("- AES:", !!result.identities.aes);
|
|
244
|
+
console.log("- Signal:", !!result.identities.signal);
|
|
245
|
+
console.log("- PGP:", !!result.identities.pgp);
|
|
246
|
+
console.log("- MLS:", !!result.identities.mls);
|
|
247
|
+
console.log("- SFrame:", !!result.identities.sframe);
|
|
248
|
+
}
|
|
249
|
+
// Restore original console methods at the end
|
|
250
|
+
errorSuppressionActive = false;
|
|
251
|
+
console.log = originalLog;
|
|
252
|
+
console.error = originalError;
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// Funzione principale per eseguire gli esempi
|
|
259
|
+
export function runCryptoIdentityExamples() {
|
|
260
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
261
|
+
var error_1;
|
|
262
|
+
return __generator(this, function (_a) {
|
|
263
|
+
switch (_a.label) {
|
|
264
|
+
case 0:
|
|
265
|
+
_a.trys.push([0, 4, 5, 6]);
|
|
266
|
+
return [4 /*yield*/, basicIdentityExample()];
|
|
267
|
+
case 1:
|
|
268
|
+
_a.sent();
|
|
269
|
+
return [4 /*yield*/, regenerateIdentityExample()];
|
|
270
|
+
case 2:
|
|
271
|
+
_a.sent();
|
|
272
|
+
return [4 /*yield*/, setupIdentityExample()];
|
|
273
|
+
case 3:
|
|
274
|
+
_a.sent();
|
|
275
|
+
return [3 /*break*/, 6];
|
|
276
|
+
case 4:
|
|
277
|
+
error_1 = _a.sent();
|
|
278
|
+
console.error("❌ Errore durante l'esecuzione degli esempi:", error_1);
|
|
279
|
+
return [3 /*break*/, 6];
|
|
280
|
+
case 5:
|
|
281
|
+
// Always restore console methods
|
|
282
|
+
errorSuppressionActive = false;
|
|
283
|
+
console.log = originalLog;
|
|
284
|
+
console.error = originalError;
|
|
285
|
+
return [7 /*endfinally*/];
|
|
286
|
+
case 6: return [2 /*return*/];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// Esegui gli esempi se il file viene eseguito direttamente
|
|
292
|
+
if (typeof window === "undefined" && require.main === module) {
|
|
293
|
+
runCryptoIdentityExamples();
|
|
294
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
// Simple crypto test that actually works
|
|
38
|
+
import { randomString, sha256Hash, generateKeyPair, encrypt, decrypt, generateSymmetricKey, encryptWithSymmetricKey, decryptWithSymmetricKey, encryptTextFile, decryptTextFile, deserializePublicKey, deserializePrivateKey, deserializeSymmetricKey, } from "../crypto/index.js";
|
|
39
|
+
// Simple test function
|
|
40
|
+
function testCrypto() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
+
var randomStr, hash, keyPair, publicKey, privateKey, encryptedMessage, decryptedMessage, symmetricKey, deserializedKey, encryptedData, decryptedData, fileContent, password, encryptedFile, decryptedFile, error_1;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
_a.trys.push([0, 13, , 14]);
|
|
47
|
+
console.log("🔐 Starting crypto test...");
|
|
48
|
+
// Test 1: Random string generation
|
|
49
|
+
console.log("\n1. Testing random string generation...");
|
|
50
|
+
randomStr = randomString("test-");
|
|
51
|
+
console.log("✅ Random string:", randomStr);
|
|
52
|
+
// Test 2: Hashing
|
|
53
|
+
console.log("\n2. Testing hashing...");
|
|
54
|
+
return [4 /*yield*/, sha256Hash({
|
|
55
|
+
message: "Hello Crypto!",
|
|
56
|
+
timestamp: Date.now(),
|
|
57
|
+
})];
|
|
58
|
+
case 1:
|
|
59
|
+
hash = _a.sent();
|
|
60
|
+
console.log("✅ SHA-256 hash:", hash.substring(0, 20) + "...");
|
|
61
|
+
// Test 3: RSA key generation and encryption
|
|
62
|
+
console.log("\n3. Testing RSA encryption...");
|
|
63
|
+
return [4 /*yield*/, generateKeyPair()];
|
|
64
|
+
case 2:
|
|
65
|
+
keyPair = _a.sent();
|
|
66
|
+
console.log("✅ RSA key pair generated");
|
|
67
|
+
return [4 /*yield*/, deserializePublicKey(keyPair.publicKey)];
|
|
68
|
+
case 3:
|
|
69
|
+
publicKey = _a.sent();
|
|
70
|
+
return [4 /*yield*/, deserializePrivateKey(keyPair.privateKey)];
|
|
71
|
+
case 4:
|
|
72
|
+
privateKey = _a.sent();
|
|
73
|
+
return [4 /*yield*/, encrypt("Secret RSA message", publicKey)];
|
|
74
|
+
case 5:
|
|
75
|
+
encryptedMessage = _a.sent();
|
|
76
|
+
return [4 /*yield*/, decrypt(encryptedMessage, privateKey)];
|
|
77
|
+
case 6:
|
|
78
|
+
decryptedMessage = _a.sent();
|
|
79
|
+
console.log("✅ RSA encrypted:", encryptedMessage.substring(0, 30) + "...");
|
|
80
|
+
console.log("✅ RSA decrypted:", decryptedMessage);
|
|
81
|
+
// Test 4: AES symmetric encryption
|
|
82
|
+
console.log("\n4. Testing AES symmetric encryption...");
|
|
83
|
+
return [4 /*yield*/, generateSymmetricKey()];
|
|
84
|
+
case 7:
|
|
85
|
+
symmetricKey = _a.sent();
|
|
86
|
+
return [4 /*yield*/, deserializeSymmetricKey(symmetricKey)];
|
|
87
|
+
case 8:
|
|
88
|
+
deserializedKey = _a.sent();
|
|
89
|
+
return [4 /*yield*/, encryptWithSymmetricKey("Secret AES message", deserializedKey)];
|
|
90
|
+
case 9:
|
|
91
|
+
encryptedData = _a.sent();
|
|
92
|
+
return [4 /*yield*/, decryptWithSymmetricKey(encryptedData, deserializedKey)];
|
|
93
|
+
case 10:
|
|
94
|
+
decryptedData = _a.sent();
|
|
95
|
+
console.log("✅ AES encrypted:", encryptedData.ciphertext.substring(0, 30) + "...");
|
|
96
|
+
console.log("✅ AES decrypted:", decryptedData);
|
|
97
|
+
// Test 5: File encryption
|
|
98
|
+
console.log("\n5. Testing file encryption...");
|
|
99
|
+
fileContent = "This is a secret file content for testing!";
|
|
100
|
+
password = "testPassword123";
|
|
101
|
+
return [4 /*yield*/, encryptTextFile(fileContent, password, "test.txt")];
|
|
102
|
+
case 11:
|
|
103
|
+
encryptedFile = _a.sent();
|
|
104
|
+
return [4 /*yield*/, decryptTextFile(encryptedFile, password)];
|
|
105
|
+
case 12:
|
|
106
|
+
decryptedFile = _a.sent();
|
|
107
|
+
console.log("✅ File encrypted:", encryptedFile.fileName);
|
|
108
|
+
console.log("✅ File decrypted:", decryptedFile.textContent);
|
|
109
|
+
console.log("\n🎉 All crypto tests completed successfully!");
|
|
110
|
+
return [2 /*return*/, {
|
|
111
|
+
success: true,
|
|
112
|
+
tests: {
|
|
113
|
+
randomString: randomStr,
|
|
114
|
+
hash: hash.substring(0, 20) + "...",
|
|
115
|
+
rsaEncryption: {
|
|
116
|
+
encrypted: encryptedMessage.substring(0, 30) + "...",
|
|
117
|
+
decrypted: decryptedMessage,
|
|
118
|
+
},
|
|
119
|
+
aesEncryption: {
|
|
120
|
+
encrypted: encryptedData.ciphertext.substring(0, 30) + "...",
|
|
121
|
+
decrypted: decryptedData,
|
|
122
|
+
},
|
|
123
|
+
fileEncryption: {
|
|
124
|
+
fileName: encryptedFile.fileName,
|
|
125
|
+
decrypted: decryptedFile.textContent,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}];
|
|
129
|
+
case 13:
|
|
130
|
+
error_1 = _a.sent();
|
|
131
|
+
console.error("❌ Crypto test failed:", error_1);
|
|
132
|
+
return [2 /*return*/, {
|
|
133
|
+
success: false,
|
|
134
|
+
error: error_1 instanceof Error ? error_1.message : "Unknown error",
|
|
135
|
+
}];
|
|
136
|
+
case 14: return [2 /*return*/];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// Run the test
|
|
142
|
+
testCrypto()
|
|
143
|
+
.then(function (result) {
|
|
144
|
+
console.log("\n📊 Final Result:");
|
|
145
|
+
console.log(JSON.stringify(result, null, 2));
|
|
146
|
+
})
|
|
147
|
+
.catch(function (error) {
|
|
148
|
+
console.error("💥 Test execution failed:", error);
|
|
149
|
+
});
|