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,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PGP Example - Simple and Immediate
|
|
3
|
+
* Demonstrates basic PGP functionality:
|
|
4
|
+
* - Key generation
|
|
5
|
+
* - Message encryption/decryption
|
|
6
|
+
* - Digital signing
|
|
7
|
+
* - Signature verification
|
|
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 __values = (this && this.__values) || function(o) {
|
|
46
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
47
|
+
if (m) return m.call(o);
|
|
48
|
+
if (o && typeof o.length === "number") return {
|
|
49
|
+
next: function () {
|
|
50
|
+
if (o && i >= o.length) o = void 0;
|
|
51
|
+
return { value: o && o[i++], done: !o };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
55
|
+
};
|
|
56
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
57
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
58
|
+
if (!m) return o;
|
|
59
|
+
var i = m.call(o), r, ar = [], e;
|
|
60
|
+
try {
|
|
61
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
62
|
+
}
|
|
63
|
+
catch (error) { e = { error: error }; }
|
|
64
|
+
finally {
|
|
65
|
+
try {
|
|
66
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
67
|
+
}
|
|
68
|
+
finally { if (e) throw e.error; }
|
|
69
|
+
}
|
|
70
|
+
return ar;
|
|
71
|
+
};
|
|
72
|
+
import { createPGPManager, generatePGPKeyPair, encryptPGPMessage, decryptPGPMessage, signPGPMessage, verifyPGPSignature, demonstratePGP, } from "../crypto/index.js";
|
|
73
|
+
// Simple PGP usage example
|
|
74
|
+
function simplePGPExample() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
+
var aliceKeys, bobKeys, message, encrypted, decrypted, signedMessage, signature, verification, error_1;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
_a.trys.push([0, 7, , 8]);
|
|
81
|
+
console.log("🔐 Starting Simple PGP Example");
|
|
82
|
+
console.log("=".repeat(40));
|
|
83
|
+
// Method 1: Using factory functions (simplest)
|
|
84
|
+
console.log("\n📋 Method 1: Factory Functions");
|
|
85
|
+
return [4 /*yield*/, generatePGPKeyPair("Alice", "alice@example.com", "alice123")];
|
|
86
|
+
case 1:
|
|
87
|
+
aliceKeys = _a.sent();
|
|
88
|
+
return [4 /*yield*/, generatePGPKeyPair("Bob", "bob@example.com", "bob123")];
|
|
89
|
+
case 2:
|
|
90
|
+
bobKeys = _a.sent();
|
|
91
|
+
console.log("✅ Key pairs generated");
|
|
92
|
+
console.log("Alice Key ID:", aliceKeys.keyId);
|
|
93
|
+
console.log("Bob Key ID:", bobKeys.keyId);
|
|
94
|
+
message = "Hello Bob! This is a secret message from Alice. 🔐";
|
|
95
|
+
return [4 /*yield*/, encryptPGPMessage(message, bobKeys.publicKey)];
|
|
96
|
+
case 3:
|
|
97
|
+
encrypted = _a.sent();
|
|
98
|
+
console.log("✅ Message encrypted");
|
|
99
|
+
console.log("Encrypted message length:", encrypted.message.length);
|
|
100
|
+
return [4 /*yield*/, decryptPGPMessage(encrypted.message, bobKeys.privateKey, "bob123")];
|
|
101
|
+
case 4:
|
|
102
|
+
decrypted = _a.sent();
|
|
103
|
+
console.log("✅ Message decrypted");
|
|
104
|
+
console.log("Original message:", message);
|
|
105
|
+
console.log("Decrypted message:", decrypted);
|
|
106
|
+
console.log("Messages match:", message === decrypted);
|
|
107
|
+
signedMessage = "This is a signed message from Alice. ✍️";
|
|
108
|
+
return [4 /*yield*/, signPGPMessage(signedMessage, aliceKeys.privateKey, "alice123")];
|
|
109
|
+
case 5:
|
|
110
|
+
signature = _a.sent();
|
|
111
|
+
console.log("✅ Message signed");
|
|
112
|
+
console.log("Signature length:", signature.signature.length);
|
|
113
|
+
return [4 /*yield*/, verifyPGPSignature(signedMessage, signature.signature, aliceKeys.publicKey)];
|
|
114
|
+
case 6:
|
|
115
|
+
verification = _a.sent();
|
|
116
|
+
console.log("✅ Signature verified");
|
|
117
|
+
console.log("Signature valid:", verification.valid);
|
|
118
|
+
console.log("\n🎉 Simple PGP Example completed successfully!");
|
|
119
|
+
return [2 /*return*/, {
|
|
120
|
+
success: true,
|
|
121
|
+
messageDecrypted: message === decrypted,
|
|
122
|
+
signatureValid: verification.valid,
|
|
123
|
+
}];
|
|
124
|
+
case 7:
|
|
125
|
+
error_1 = _a.sent();
|
|
126
|
+
console.error("❌ Simple PGP Example failed:", error_1);
|
|
127
|
+
return [2 /*return*/, {
|
|
128
|
+
success: false,
|
|
129
|
+
error: error_1 instanceof Error ? error_1.message : "Unknown error",
|
|
130
|
+
}];
|
|
131
|
+
case 8: return [2 /*return*/];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
// Advanced PGP usage with manager
|
|
137
|
+
function advancedPGPExample() {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
+
var manager, users, userKeys, users_1, users_1_1, user, keys, e_1_1, groupMessage, encryptedForBob, encryptedForCharlie, bobDecrypted, charlieDecrypted, userKeys_1, userKeys_1_1, _a, name_1, keys, keyInfo, e_2_1, aliceKeyArmored, aliceKeyBinary, importedKey, error_2;
|
|
140
|
+
var e_1, _b, e_2, _c;
|
|
141
|
+
return __generator(this, function (_d) {
|
|
142
|
+
switch (_d.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
_d.trys.push([0, 25, 26, 27]);
|
|
145
|
+
console.log("\n🔐 Starting Advanced PGP Example");
|
|
146
|
+
console.log("=".repeat(40));
|
|
147
|
+
return [4 /*yield*/, createPGPManager()];
|
|
148
|
+
case 1:
|
|
149
|
+
// Method 2: Using PGPManager (more control)
|
|
150
|
+
manager = _d.sent();
|
|
151
|
+
console.log("✅ PGP Manager created");
|
|
152
|
+
users = [
|
|
153
|
+
{ name: "Alice", email: "alice@example.com", passphrase: "alice123" },
|
|
154
|
+
{ name: "Bob", email: "bob@example.com", passphrase: "bob123" },
|
|
155
|
+
{
|
|
156
|
+
name: "Charlie",
|
|
157
|
+
email: "charlie@example.com",
|
|
158
|
+
passphrase: "charlie123",
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
userKeys = new Map();
|
|
162
|
+
_d.label = 2;
|
|
163
|
+
case 2:
|
|
164
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
165
|
+
users_1 = __values(users), users_1_1 = users_1.next();
|
|
166
|
+
_d.label = 3;
|
|
167
|
+
case 3:
|
|
168
|
+
if (!!users_1_1.done) return [3 /*break*/, 6];
|
|
169
|
+
user = users_1_1.value;
|
|
170
|
+
return [4 /*yield*/, manager.generateKeyPair(user.name, user.email, user.passphrase)];
|
|
171
|
+
case 4:
|
|
172
|
+
keys = _d.sent();
|
|
173
|
+
userKeys.set(user.name, keys);
|
|
174
|
+
console.log("\u2705 ".concat(user.name, " key pair generated: ").concat(keys.keyId));
|
|
175
|
+
_d.label = 5;
|
|
176
|
+
case 5:
|
|
177
|
+
users_1_1 = users_1.next();
|
|
178
|
+
return [3 /*break*/, 3];
|
|
179
|
+
case 6: return [3 /*break*/, 9];
|
|
180
|
+
case 7:
|
|
181
|
+
e_1_1 = _d.sent();
|
|
182
|
+
e_1 = { error: e_1_1 };
|
|
183
|
+
return [3 /*break*/, 9];
|
|
184
|
+
case 8:
|
|
185
|
+
try {
|
|
186
|
+
if (users_1_1 && !users_1_1.done && (_b = users_1.return)) _b.call(users_1);
|
|
187
|
+
}
|
|
188
|
+
finally { if (e_1) throw e_1.error; }
|
|
189
|
+
return [7 /*endfinally*/];
|
|
190
|
+
case 9:
|
|
191
|
+
// Test group messaging (Alice sends to Bob and Charlie)
|
|
192
|
+
console.log("\n📧 Group Messaging Test");
|
|
193
|
+
groupMessage = "Hello everyone! This is a group message from Alice. 👥";
|
|
194
|
+
return [4 /*yield*/, manager.encryptMessage(groupMessage, userKeys.get("Bob").publicKey, userKeys.get("Alice").privateKey, // Alice signs
|
|
195
|
+
"alice123")];
|
|
196
|
+
case 10:
|
|
197
|
+
encryptedForBob = _d.sent();
|
|
198
|
+
return [4 /*yield*/, manager.encryptMessage(groupMessage, userKeys.get("Charlie").publicKey, userKeys.get("Alice").privateKey, // Alice signs
|
|
199
|
+
"alice123")];
|
|
200
|
+
case 11:
|
|
201
|
+
encryptedForCharlie = _d.sent();
|
|
202
|
+
console.log("✅ Messages encrypted for Bob and Charlie");
|
|
203
|
+
return [4 /*yield*/, manager.decryptMessage(encryptedForBob.message, userKeys.get("Bob").privateKey, "bob123")];
|
|
204
|
+
case 12:
|
|
205
|
+
bobDecrypted = _d.sent();
|
|
206
|
+
return [4 /*yield*/, manager.decryptMessage(encryptedForCharlie.message, userKeys.get("Charlie").privateKey, "charlie123")];
|
|
207
|
+
case 13:
|
|
208
|
+
charlieDecrypted = _d.sent();
|
|
209
|
+
console.log("✅ Messages decrypted by Bob and Charlie");
|
|
210
|
+
console.log("Bob received:", bobDecrypted);
|
|
211
|
+
console.log("Charlie received:", charlieDecrypted);
|
|
212
|
+
// Test key information
|
|
213
|
+
console.log("\n🔍 Key Information");
|
|
214
|
+
_d.label = 14;
|
|
215
|
+
case 14:
|
|
216
|
+
_d.trys.push([14, 19, 20, 21]);
|
|
217
|
+
userKeys_1 = __values(userKeys), userKeys_1_1 = userKeys_1.next();
|
|
218
|
+
_d.label = 15;
|
|
219
|
+
case 15:
|
|
220
|
+
if (!!userKeys_1_1.done) return [3 /*break*/, 18];
|
|
221
|
+
_a = __read(userKeys_1_1.value, 2), name_1 = _a[0], keys = _a[1];
|
|
222
|
+
return [4 /*yield*/, manager.getKeyInfo(keys.publicKey)];
|
|
223
|
+
case 16:
|
|
224
|
+
keyInfo = _d.sent();
|
|
225
|
+
console.log("".concat(name_1, ":"), {
|
|
226
|
+
keyId: keyInfo.keyId,
|
|
227
|
+
fingerprint: keyInfo.fingerprint,
|
|
228
|
+
algorithm: keyInfo.algorithm,
|
|
229
|
+
created: keyInfo.created,
|
|
230
|
+
isPrivate: keyInfo.isPrivate,
|
|
231
|
+
isPublic: keyInfo.isPublic,
|
|
232
|
+
});
|
|
233
|
+
_d.label = 17;
|
|
234
|
+
case 17:
|
|
235
|
+
userKeys_1_1 = userKeys_1.next();
|
|
236
|
+
return [3 /*break*/, 15];
|
|
237
|
+
case 18: return [3 /*break*/, 21];
|
|
238
|
+
case 19:
|
|
239
|
+
e_2_1 = _d.sent();
|
|
240
|
+
e_2 = { error: e_2_1 };
|
|
241
|
+
return [3 /*break*/, 21];
|
|
242
|
+
case 20:
|
|
243
|
+
try {
|
|
244
|
+
if (userKeys_1_1 && !userKeys_1_1.done && (_c = userKeys_1.return)) _c.call(userKeys_1);
|
|
245
|
+
}
|
|
246
|
+
finally { if (e_2) throw e_2.error; }
|
|
247
|
+
return [7 /*endfinally*/];
|
|
248
|
+
case 21:
|
|
249
|
+
// Test key export/import
|
|
250
|
+
console.log("\n📤 Key Export/Import Test");
|
|
251
|
+
return [4 /*yield*/, manager.exportKey(userKeys.get("Alice").publicKey, "armored")];
|
|
252
|
+
case 22:
|
|
253
|
+
aliceKeyArmored = _d.sent();
|
|
254
|
+
return [4 /*yield*/, manager.exportKey(userKeys.get("Alice").publicKey, "binary")];
|
|
255
|
+
case 23:
|
|
256
|
+
aliceKeyBinary = _d.sent();
|
|
257
|
+
console.log("✅ Alice's key exported in armored and binary formats");
|
|
258
|
+
console.log("Armored length:", aliceKeyArmored.length);
|
|
259
|
+
console.log("Binary length:", aliceKeyBinary.length);
|
|
260
|
+
return [4 /*yield*/, manager.importKey(aliceKeyBinary, "binary")];
|
|
261
|
+
case 24:
|
|
262
|
+
importedKey = _d.sent();
|
|
263
|
+
console.log("✅ Key imported from binary format");
|
|
264
|
+
console.log("Imported key matches original:", importedKey === userKeys.get("Alice").publicKey);
|
|
265
|
+
console.log("\n🎉 Advanced PGP Example completed successfully!");
|
|
266
|
+
return [2 /*return*/, {
|
|
267
|
+
success: true,
|
|
268
|
+
groupMessaging: true,
|
|
269
|
+
keyManagement: true,
|
|
270
|
+
exportImport: true,
|
|
271
|
+
}];
|
|
272
|
+
case 25:
|
|
273
|
+
error_2 = _d.sent();
|
|
274
|
+
console.error("❌ Advanced PGP Example failed:", error_2);
|
|
275
|
+
return [2 /*return*/, {
|
|
276
|
+
success: false,
|
|
277
|
+
error: error_2 instanceof Error ? error_2.message : "Unknown error",
|
|
278
|
+
}];
|
|
279
|
+
case 26:
|
|
280
|
+
// Clean up
|
|
281
|
+
if (typeof manager !== "undefined") {
|
|
282
|
+
manager.destroy();
|
|
283
|
+
}
|
|
284
|
+
return [7 /*endfinally*/];
|
|
285
|
+
case 27: return [2 /*return*/];
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
// Run all examples
|
|
291
|
+
function runAllPGPExamples() {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
293
|
+
var simpleResult, advancedResult, demoResult, allPassed;
|
|
294
|
+
return __generator(this, function (_a) {
|
|
295
|
+
switch (_a.label) {
|
|
296
|
+
case 0:
|
|
297
|
+
console.log("🚀 Running All PGP Examples");
|
|
298
|
+
console.log("=".repeat(50));
|
|
299
|
+
// Example 1: Simple usage
|
|
300
|
+
console.log("\n=== Example 1: Simple PGP Usage ===");
|
|
301
|
+
return [4 /*yield*/, simplePGPExample()];
|
|
302
|
+
case 1:
|
|
303
|
+
simpleResult = _a.sent();
|
|
304
|
+
// Example 2: Advanced usage
|
|
305
|
+
console.log("\n=== Example 2: Advanced PGP Usage ===");
|
|
306
|
+
return [4 /*yield*/, advancedPGPExample()];
|
|
307
|
+
case 2:
|
|
308
|
+
advancedResult = _a.sent();
|
|
309
|
+
// Example 3: Full demonstration
|
|
310
|
+
console.log("\n=== Example 3: Full PGP Demonstration ===");
|
|
311
|
+
return [4 /*yield*/, demonstratePGP()];
|
|
312
|
+
case 3:
|
|
313
|
+
demoResult = _a.sent();
|
|
314
|
+
console.log("\n📊 Final Results:");
|
|
315
|
+
console.log("Simple PGP:", simpleResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
316
|
+
console.log("Advanced PGP:", advancedResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
317
|
+
console.log("Full Demo:", demoResult.success ? "✅ PASSED" : "❌ FAILED");
|
|
318
|
+
allPassed = simpleResult.success && advancedResult.success && demoResult.success;
|
|
319
|
+
if (allPassed) {
|
|
320
|
+
console.log("\n🎉 All PGP examples completed successfully!");
|
|
321
|
+
console.log("🔐 PGP Features Demonstrated:");
|
|
322
|
+
console.log(" ✅ Key generation (RSA 4096-bit)");
|
|
323
|
+
console.log(" ✅ Message encryption/decryption");
|
|
324
|
+
console.log(" ✅ Digital signing and verification");
|
|
325
|
+
console.log(" ✅ Key management and information");
|
|
326
|
+
console.log(" ✅ Key export/import (armored/binary)");
|
|
327
|
+
console.log(" ✅ Group messaging with signing");
|
|
328
|
+
console.log(" ✅ OpenPGP standard compliance");
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
console.log("\n❌ Some PGP examples failed");
|
|
332
|
+
}
|
|
333
|
+
return [2 /*return*/, {
|
|
334
|
+
simple: simpleResult,
|
|
335
|
+
advanced: advancedResult,
|
|
336
|
+
demo: demoResult,
|
|
337
|
+
allPassed: allPassed,
|
|
338
|
+
}];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// Run the examples
|
|
344
|
+
if (require.main === module) {
|
|
345
|
+
runAllPGPExamples()
|
|
346
|
+
.then(function (result) {
|
|
347
|
+
console.log("\n📊 Final Test Summary:");
|
|
348
|
+
console.log(JSON.stringify(result, null, 2));
|
|
349
|
+
})
|
|
350
|
+
.catch(function (error) {
|
|
351
|
+
console.error("💥 PGP examples execution failed:", error);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
export { simplePGPExample, advancedPGPExample, runAllPGPExamples };
|
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
// Random Generation test
|
|
38
|
+
import { generateRandomString, randomBytes, randomInt, randomFloat, randomBool, randomUUID, createDeterministicRandom, chance, randomChoice, randomShuffle, randomColor, randomPassword, randomSeedPhrase, } from "../crypto/index.js";
|
|
39
|
+
// Test Random Generation
|
|
40
|
+
function testRandomGeneration() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
+
var randomStr, bytes, randomNum, randomFloatVal, randomBoolVal, uuid, detRandom, detInt1, detInt2, detFloat, detBool, detString, detGuid, chanceInstance, chanceInt, chanceFloat, chanceBool, testArray, choice, shuffled, color, password, seedPhrase, det1, det2, val1_1, val1_2, val2_1, val2_2;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
try {
|
|
45
|
+
console.log("🎲 Starting Random Generation test...");
|
|
46
|
+
// Test 1: Basic random string generation
|
|
47
|
+
console.log("\n1. Testing basic random string generation...");
|
|
48
|
+
randomStr = generateRandomString(16, "test-");
|
|
49
|
+
console.log("✅ Random string:", randomStr);
|
|
50
|
+
// Test 2: Random bytes
|
|
51
|
+
console.log("\n2. Testing random bytes...");
|
|
52
|
+
bytes = randomBytes(8);
|
|
53
|
+
console.log("✅ Random bytes:", Array.from(bytes)
|
|
54
|
+
.map(function (b) { return b.toString(16).padStart(2, "0"); })
|
|
55
|
+
.join(""));
|
|
56
|
+
// Test 3: Random integer
|
|
57
|
+
console.log("\n3. Testing random integer...");
|
|
58
|
+
randomNum = randomInt(1, 100);
|
|
59
|
+
console.log("✅ Random integer (1-100):", randomNum);
|
|
60
|
+
// Test 4: Random float
|
|
61
|
+
console.log("\n4. Testing random float...");
|
|
62
|
+
randomFloatVal = randomFloat();
|
|
63
|
+
console.log("✅ Random float:", randomFloatVal);
|
|
64
|
+
// Test 5: Random boolean
|
|
65
|
+
console.log("\n5. Testing random boolean...");
|
|
66
|
+
randomBoolVal = randomBool();
|
|
67
|
+
console.log("✅ Random boolean:", randomBoolVal);
|
|
68
|
+
// Test 6: Random UUID
|
|
69
|
+
console.log("\n6. Testing random UUID...");
|
|
70
|
+
uuid = randomUUID();
|
|
71
|
+
console.log("✅ Random UUID:", uuid);
|
|
72
|
+
// Test 7: Deterministic random
|
|
73
|
+
console.log("\n7. Testing deterministic random...");
|
|
74
|
+
detRandom = createDeterministicRandom("test-seed");
|
|
75
|
+
detInt1 = detRandom.integer(1, 100);
|
|
76
|
+
detInt2 = detRandom.integer(1, 100);
|
|
77
|
+
detFloat = detRandom.floating(0, 1, 4);
|
|
78
|
+
detBool = detRandom.bool();
|
|
79
|
+
detString = detRandom.string(10);
|
|
80
|
+
detGuid = detRandom.guid();
|
|
81
|
+
console.log("✅ Deterministic integer 1:", detInt1);
|
|
82
|
+
console.log("✅ Deterministic integer 2:", detInt2);
|
|
83
|
+
console.log("✅ Deterministic float:", detFloat);
|
|
84
|
+
console.log("✅ Deterministic boolean:", detBool);
|
|
85
|
+
console.log("✅ Deterministic string:", detString);
|
|
86
|
+
console.log("✅ Deterministic GUID:", detGuid);
|
|
87
|
+
// Test 8: Chance.js compatibility
|
|
88
|
+
console.log("\n8. Testing Chance.js compatibility...");
|
|
89
|
+
chanceInstance = chance("chance-seed");
|
|
90
|
+
chanceInt = chanceInstance.integer(1, 50);
|
|
91
|
+
chanceFloat = chanceInstance.floating(0, 10, 2);
|
|
92
|
+
chanceBool = chanceInstance.bool();
|
|
93
|
+
console.log("✅ Chance integer:", chanceInt);
|
|
94
|
+
console.log("✅ Chance float:", chanceFloat);
|
|
95
|
+
console.log("✅ Chance boolean:", chanceBool);
|
|
96
|
+
// Test 9: Array utilities
|
|
97
|
+
console.log("\n9. Testing array utilities...");
|
|
98
|
+
testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
99
|
+
choice = randomChoice(testArray);
|
|
100
|
+
shuffled = randomShuffle(testArray);
|
|
101
|
+
console.log("✅ Random choice from array:", choice);
|
|
102
|
+
console.log("✅ Shuffled array:", shuffled);
|
|
103
|
+
// Test 10: Random color
|
|
104
|
+
console.log("\n10. Testing random color...");
|
|
105
|
+
color = randomColor();
|
|
106
|
+
console.log("✅ Random color:", color);
|
|
107
|
+
// Test 11: Random password
|
|
108
|
+
console.log("\n11. Testing random password...");
|
|
109
|
+
password = randomPassword({
|
|
110
|
+
length: 16,
|
|
111
|
+
includeUppercase: true,
|
|
112
|
+
includeLowercase: true,
|
|
113
|
+
includeNumbers: true,
|
|
114
|
+
includeSymbols: true,
|
|
115
|
+
excludeSimilar: true,
|
|
116
|
+
});
|
|
117
|
+
console.log("✅ Random password:", password);
|
|
118
|
+
// Test 12: Random seed phrase
|
|
119
|
+
console.log("\n12. Testing random seed phrase...");
|
|
120
|
+
seedPhrase = randomSeedPhrase(12);
|
|
121
|
+
console.log("✅ Random seed phrase:", seedPhrase.join(" "));
|
|
122
|
+
// Test 13: Deterministic consistency
|
|
123
|
+
console.log("\n13. Testing deterministic consistency...");
|
|
124
|
+
det1 = createDeterministicRandom("consistency-test");
|
|
125
|
+
det2 = createDeterministicRandom("consistency-test");
|
|
126
|
+
val1_1 = det1.integer(1, 100);
|
|
127
|
+
val1_2 = det1.integer(1, 100);
|
|
128
|
+
val2_1 = det2.integer(1, 100);
|
|
129
|
+
val2_2 = det2.integer(1, 100);
|
|
130
|
+
console.log("✅ Deterministic consistency test:");
|
|
131
|
+
console.log(" Same seed, first value:", val1_1 === val2_1 ? "✅ MATCH" : "❌ MISMATCH");
|
|
132
|
+
console.log(" Same seed, second value:", val1_2 === val2_2 ? "✅ MATCH" : "❌ MISMATCH");
|
|
133
|
+
console.log("\n🎉 All Random Generation tests completed successfully!");
|
|
134
|
+
return [2 /*return*/, {
|
|
135
|
+
success: true,
|
|
136
|
+
tests: {
|
|
137
|
+
randomString: randomStr,
|
|
138
|
+
randomBytes: Array.from(bytes)
|
|
139
|
+
.map(function (b) { return b.toString(16).padStart(2, "0"); })
|
|
140
|
+
.join(""),
|
|
141
|
+
randomInt: randomNum,
|
|
142
|
+
randomFloat: randomFloatVal,
|
|
143
|
+
randomBool: randomBoolVal,
|
|
144
|
+
randomUUID: uuid,
|
|
145
|
+
deterministic: {
|
|
146
|
+
int1: detInt1,
|
|
147
|
+
int2: detInt2,
|
|
148
|
+
float: detFloat,
|
|
149
|
+
bool: detBool,
|
|
150
|
+
string: detString,
|
|
151
|
+
guid: detGuid,
|
|
152
|
+
},
|
|
153
|
+
chance: {
|
|
154
|
+
int: chanceInt,
|
|
155
|
+
float: chanceFloat,
|
|
156
|
+
bool: chanceBool,
|
|
157
|
+
},
|
|
158
|
+
arrayUtils: {
|
|
159
|
+
choice: choice,
|
|
160
|
+
shuffledLength: shuffled.length,
|
|
161
|
+
},
|
|
162
|
+
color: color,
|
|
163
|
+
password: password,
|
|
164
|
+
seedPhrase: seedPhrase.join(" "),
|
|
165
|
+
consistency: {
|
|
166
|
+
firstMatch: val1_1 === val2_1,
|
|
167
|
+
secondMatch: val1_2 === val2_2,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
}];
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error("❌ Random Generation test error:", error);
|
|
174
|
+
return [2 /*return*/, {
|
|
175
|
+
success: false,
|
|
176
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
177
|
+
}];
|
|
178
|
+
}
|
|
179
|
+
return [2 /*return*/];
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// Run the test
|
|
184
|
+
testRandomGeneration()
|
|
185
|
+
.then(function (result) {
|
|
186
|
+
console.log("\n📊 Final Result:");
|
|
187
|
+
console.log(JSON.stringify(result, null, 2));
|
|
188
|
+
})
|
|
189
|
+
.catch(function (error) {
|
|
190
|
+
console.error("💥 Test execution failed:", error);
|
|
191
|
+
});
|