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,339 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
+
if (m) return m.call(o);
|
|
40
|
+
if (o && typeof o.length === "number") return {
|
|
41
|
+
next: function () {
|
|
42
|
+
if (o && i >= o.length) o = void 0;
|
|
43
|
+
return { value: o && o[i++], done: !o };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Types of errors that can occur in the application
|
|
50
|
+
*/
|
|
51
|
+
export var ErrorType;
|
|
52
|
+
(function (ErrorType) {
|
|
53
|
+
ErrorType["AUTHENTICATION"] = "AuthenticationError";
|
|
54
|
+
ErrorType["AUTHORIZATION"] = "AuthorizationError";
|
|
55
|
+
ErrorType["VALIDATION"] = "ValidationError";
|
|
56
|
+
ErrorType["NETWORK"] = "NetworkError";
|
|
57
|
+
ErrorType["DATABASE"] = "DatabaseError";
|
|
58
|
+
ErrorType["WALLET"] = "WalletError";
|
|
59
|
+
ErrorType["STORAGE"] = "StorageError";
|
|
60
|
+
ErrorType["ENCRYPTION"] = "EncryptionError";
|
|
61
|
+
ErrorType["SIGNATURE"] = "SignatureError";
|
|
62
|
+
ErrorType["ENVIRONMENT"] = "EnvironmentError";
|
|
63
|
+
ErrorType["SECURITY"] = "SecurityError";
|
|
64
|
+
ErrorType["GUN"] = "GunError";
|
|
65
|
+
ErrorType["STEALTH"] = "StealthError";
|
|
66
|
+
ErrorType["WEBAUTHN"] = "WebAuthnError";
|
|
67
|
+
ErrorType["PLUGIN"] = "PluginError";
|
|
68
|
+
ErrorType["UNKNOWN"] = "UnknownError";
|
|
69
|
+
ErrorType["CONNECTOR"] = "ConnectorError";
|
|
70
|
+
ErrorType["GENERAL"] = "GeneralError";
|
|
71
|
+
ErrorType["CONTRACT"] = "ContractError";
|
|
72
|
+
ErrorType["BIP32"] = "BIP32Error";
|
|
73
|
+
ErrorType["ETHEREUM"] = "EthereumError";
|
|
74
|
+
ErrorType["BITCOIN"] = "BitcoinError";
|
|
75
|
+
})(ErrorType || (ErrorType = {}));
|
|
76
|
+
/**
|
|
77
|
+
* Wrapper to standardize errors
|
|
78
|
+
* @param type - Error type
|
|
79
|
+
* @param code - Error code
|
|
80
|
+
* @param message - Error message
|
|
81
|
+
* @param originalError - Original error
|
|
82
|
+
* @returns A structured error object
|
|
83
|
+
*/
|
|
84
|
+
export function createError(type, code, message, originalError) {
|
|
85
|
+
return {
|
|
86
|
+
type: type,
|
|
87
|
+
code: code,
|
|
88
|
+
message: message,
|
|
89
|
+
originalError: originalError,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Centralized error handler
|
|
95
|
+
*/
|
|
96
|
+
var ErrorHandler = /** @class */ (function () {
|
|
97
|
+
function ErrorHandler() {
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set an external logging service for production error monitoring
|
|
101
|
+
* @param logger - External logger function to send errors to a monitoring service
|
|
102
|
+
*/
|
|
103
|
+
ErrorHandler.setExternalLogger = function (logger) {
|
|
104
|
+
this.externalLogger = logger;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Handles an error by logging it and notifying listeners
|
|
108
|
+
* @param error - The error to handle
|
|
109
|
+
*/
|
|
110
|
+
ErrorHandler.handleError = function (error) {
|
|
111
|
+
// Log essential errors only
|
|
112
|
+
if (error.type === ErrorType.AUTHENTICATION ||
|
|
113
|
+
error.type === ErrorType.AUTHORIZATION ||
|
|
114
|
+
error.type === ErrorType.SECURITY) {
|
|
115
|
+
// Ensure console.error is available and safe to use
|
|
116
|
+
if (typeof console !== "undefined" && console.error) {
|
|
117
|
+
console.error("[".concat(error.type, "] ").concat(error.code, ": ").concat(error.message));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Store the error in memory
|
|
121
|
+
this.errors.push(error);
|
|
122
|
+
// Keep only the last maxErrors
|
|
123
|
+
if (this.errors.length > this.maxErrors) {
|
|
124
|
+
this.errors = this.errors.slice(-this.maxErrors);
|
|
125
|
+
}
|
|
126
|
+
// Send to external logger if set (for production monitoring)
|
|
127
|
+
if (this.externalLogger) {
|
|
128
|
+
try {
|
|
129
|
+
this.externalLogger(error);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
// Fallback logging for external logger errors
|
|
133
|
+
console.error("Failed to send error to external logger:", e);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Notify all listeners
|
|
137
|
+
this.listeners.forEach(function (listener) {
|
|
138
|
+
try {
|
|
139
|
+
listener(error);
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
// Silent error to prevent infinite loops
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Handles a raw error by converting it to ShogunError
|
|
148
|
+
* @param type - Error type
|
|
149
|
+
* @param code - Error code
|
|
150
|
+
* @param message - Error message
|
|
151
|
+
* @param originalError - Original error
|
|
152
|
+
* @param logLevel - Log level for the error
|
|
153
|
+
*/
|
|
154
|
+
ErrorHandler.handle = function (type, code, message, originalError, logLevel) {
|
|
155
|
+
if (logLevel === void 0) { logLevel = "error"; }
|
|
156
|
+
// Create a formatted error message (tests expect the plain message)
|
|
157
|
+
var finalMessage = message;
|
|
158
|
+
// Log the error
|
|
159
|
+
switch (logLevel) {
|
|
160
|
+
case "debug":
|
|
161
|
+
console.log("[".concat(type, "] ").concat(code, ": ").concat(finalMessage));
|
|
162
|
+
break;
|
|
163
|
+
case "warn":
|
|
164
|
+
console.log("[".concat(type, "] ").concat(code, ": ").concat(finalMessage));
|
|
165
|
+
break;
|
|
166
|
+
case "info":
|
|
167
|
+
console.log("[".concat(type, "] ").concat(code, ": ").concat(finalMessage));
|
|
168
|
+
break;
|
|
169
|
+
case "error":
|
|
170
|
+
default:
|
|
171
|
+
console.log("[".concat(type, "] ").concat(code, ": ").concat(finalMessage));
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
var error = createError(type, code, finalMessage, originalError);
|
|
175
|
+
this.handleError(error);
|
|
176
|
+
return error;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Handles errors and throws them as standardized ShogunError objects
|
|
180
|
+
* @param type - Error type
|
|
181
|
+
* @param code - Error code
|
|
182
|
+
* @param message - Error message
|
|
183
|
+
* @param originalError - Original error
|
|
184
|
+
* @throws ShogunError
|
|
185
|
+
*/
|
|
186
|
+
ErrorHandler.handleAndThrow = function (type, code, message, originalError) {
|
|
187
|
+
var error = this.handle(type, code, message, originalError);
|
|
188
|
+
throw error;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Retrieves the last N errors
|
|
192
|
+
* @param count - Number of errors to retrieve
|
|
193
|
+
* @returns List of most recent errors
|
|
194
|
+
*/
|
|
195
|
+
ErrorHandler.getRecentErrors = function (count) {
|
|
196
|
+
if (count === void 0) { count = 10; }
|
|
197
|
+
return this.errors.slice(-Math.min(count, this.errors.length));
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Adds a listener for errors
|
|
201
|
+
* @param listener - Function that will be called when an error occurs
|
|
202
|
+
*/
|
|
203
|
+
ErrorHandler.addListener = function (listener) {
|
|
204
|
+
this.listeners.push(listener);
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Removes an error listener
|
|
208
|
+
* @param listener - Function to remove
|
|
209
|
+
*/
|
|
210
|
+
ErrorHandler.removeListener = function (listener) {
|
|
211
|
+
var index = this.listeners.indexOf(listener);
|
|
212
|
+
if (index !== -1) {
|
|
213
|
+
this.listeners.splice(index, 1);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Notifies all listeners of an error
|
|
218
|
+
* @param error - Error to notify
|
|
219
|
+
*/
|
|
220
|
+
ErrorHandler.notifyListeners = function (error) {
|
|
221
|
+
var e_1, _a;
|
|
222
|
+
try {
|
|
223
|
+
for (var _b = __values(this.listeners), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
224
|
+
var listener = _c.value;
|
|
225
|
+
try {
|
|
226
|
+
listener(error);
|
|
227
|
+
}
|
|
228
|
+
catch (listenerError) {
|
|
229
|
+
console.error("Error in error listener: ".concat(listenerError));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
234
|
+
finally {
|
|
235
|
+
try {
|
|
236
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
237
|
+
}
|
|
238
|
+
finally { if (e_1) throw e_1.error; }
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Helper function to format error messages from native errors
|
|
243
|
+
* @param error - Error to format
|
|
244
|
+
* @returns Formatted error message
|
|
245
|
+
*/
|
|
246
|
+
ErrorHandler.formatError = function (error) {
|
|
247
|
+
if (!error) {
|
|
248
|
+
return "Unknown error";
|
|
249
|
+
}
|
|
250
|
+
if (error instanceof Error) {
|
|
251
|
+
return "".concat(error.name, ": ").concat(error.message);
|
|
252
|
+
}
|
|
253
|
+
if (typeof error === "string") {
|
|
254
|
+
return error;
|
|
255
|
+
}
|
|
256
|
+
if (typeof error === "object") {
|
|
257
|
+
try {
|
|
258
|
+
return JSON.stringify(error);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
return "Object: ".concat(Object.prototype.toString.call(error));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return String(error);
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Error handling with retry logic
|
|
268
|
+
*/
|
|
269
|
+
ErrorHandler.withRetry = function (fn_1, errorType_1, errorCode_1) {
|
|
270
|
+
return __awaiter(this, arguments, void 0, function (fn, errorType, errorCode, maxRetries, retryDelay) {
|
|
271
|
+
var lastError, _loop_1, attempt, state_1;
|
|
272
|
+
if (maxRetries === void 0) { maxRetries = 3; }
|
|
273
|
+
if (retryDelay === void 0) { retryDelay = 1000; }
|
|
274
|
+
return __generator(this, function (_a) {
|
|
275
|
+
switch (_a.label) {
|
|
276
|
+
case 0:
|
|
277
|
+
_loop_1 = function (attempt) {
|
|
278
|
+
var _b, error_1, delay_1;
|
|
279
|
+
return __generator(this, function (_c) {
|
|
280
|
+
switch (_c.label) {
|
|
281
|
+
case 0:
|
|
282
|
+
_c.trys.push([0, 2, , 5]);
|
|
283
|
+
_b = {};
|
|
284
|
+
return [4 /*yield*/, fn()];
|
|
285
|
+
case 1: return [2 /*return*/, (_b.value = _c.sent(), _b)];
|
|
286
|
+
case 2:
|
|
287
|
+
error_1 = _c.sent();
|
|
288
|
+
lastError = error_1;
|
|
289
|
+
delay_1 = retryDelay * attempt;
|
|
290
|
+
if (!(attempt < maxRetries)) return [3 /*break*/, 4];
|
|
291
|
+
console.log("Retrying operation after ".concat(delay_1, "ms (attempt ").concat(attempt, "/").concat(maxRetries, ")"));
|
|
292
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delay_1); })];
|
|
293
|
+
case 3:
|
|
294
|
+
_c.sent();
|
|
295
|
+
_c.label = 4;
|
|
296
|
+
case 4: return [3 /*break*/, 5];
|
|
297
|
+
case 5: return [2 /*return*/];
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
};
|
|
301
|
+
attempt = 1;
|
|
302
|
+
_a.label = 1;
|
|
303
|
+
case 1:
|
|
304
|
+
if (!(attempt <= maxRetries)) return [3 /*break*/, 4];
|
|
305
|
+
return [5 /*yield**/, _loop_1(attempt)];
|
|
306
|
+
case 2:
|
|
307
|
+
state_1 = _a.sent();
|
|
308
|
+
if (typeof state_1 === "object")
|
|
309
|
+
return [2 /*return*/, state_1.value];
|
|
310
|
+
_a.label = 3;
|
|
311
|
+
case 3:
|
|
312
|
+
attempt++;
|
|
313
|
+
return [3 /*break*/, 1];
|
|
314
|
+
case 4:
|
|
315
|
+
// If we got here, all retries failed.
|
|
316
|
+
// Log the failure and rethrow the last error message for test expectations compatibility.
|
|
317
|
+
this.handle(errorType, errorCode, "Operation failed after ".concat(maxRetries, " attempts"), lastError);
|
|
318
|
+
// Prefer the original error message if available
|
|
319
|
+
if (lastError instanceof Error) {
|
|
320
|
+
throw new Error(lastError.message);
|
|
321
|
+
}
|
|
322
|
+
throw new Error(this.formatError(lastError));
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
/**
|
|
328
|
+
* Clear all stored errors
|
|
329
|
+
*/
|
|
330
|
+
ErrorHandler.clearErrors = function () {
|
|
331
|
+
this.errors = [];
|
|
332
|
+
};
|
|
333
|
+
ErrorHandler.errors = [];
|
|
334
|
+
ErrorHandler.maxErrors = 100;
|
|
335
|
+
ErrorHandler.listeners = [];
|
|
336
|
+
ErrorHandler.externalLogger = null;
|
|
337
|
+
return ErrorHandler;
|
|
338
|
+
}());
|
|
339
|
+
export { ErrorHandler };
|
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventEmitter = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Simple event emitter implementation with generic event types
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var EventEmitter = /** @class */ (function () {
|
|
5
|
+
function EventEmitter() {
|
|
9
6
|
this.events = new Map();
|
|
10
7
|
}
|
|
11
8
|
/**
|
|
12
9
|
* Registers an event listener
|
|
13
10
|
*/
|
|
14
|
-
on(event, listener) {
|
|
11
|
+
EventEmitter.prototype.on = function (event, listener) {
|
|
12
|
+
var _a;
|
|
15
13
|
if (!this.events.has(event)) {
|
|
16
14
|
this.events.set(event, []);
|
|
17
15
|
}
|
|
18
|
-
this.events.get(event)
|
|
19
|
-
}
|
|
16
|
+
(_a = this.events.get(event)) === null || _a === void 0 ? void 0 : _a.push(listener);
|
|
17
|
+
};
|
|
20
18
|
/**
|
|
21
19
|
* Emits an event with arguments
|
|
22
20
|
*/
|
|
23
|
-
emit(event, data) {
|
|
21
|
+
EventEmitter.prototype.emit = function (event, data) {
|
|
24
22
|
if (!this.events.has(event))
|
|
25
23
|
return false;
|
|
26
|
-
|
|
27
|
-
listeners.forEach((listener)
|
|
24
|
+
var listeners = this.events.get(event) || [];
|
|
25
|
+
listeners.forEach(function (listener) {
|
|
28
26
|
try {
|
|
29
27
|
listener(data);
|
|
30
28
|
}
|
|
31
29
|
catch (error) {
|
|
32
30
|
// Ensure error is properly formatted for console.error and pass Error instance
|
|
33
|
-
|
|
34
|
-
console.error(
|
|
31
|
+
var err = error instanceof Error ? error : new Error(String(error));
|
|
32
|
+
console.error("Error in event listener for ".concat(String(event), ":"), err);
|
|
35
33
|
}
|
|
36
34
|
});
|
|
37
35
|
return true;
|
|
38
|
-
}
|
|
36
|
+
};
|
|
39
37
|
/**
|
|
40
38
|
* Removes an event listener
|
|
41
39
|
*/
|
|
42
|
-
off(event, listener) {
|
|
40
|
+
EventEmitter.prototype.off = function (event, listener) {
|
|
43
41
|
if (!this.events.has(event))
|
|
44
42
|
return;
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
var listeners = this.events.get(event) || [];
|
|
44
|
+
var index = listeners.indexOf(listener);
|
|
47
45
|
if (index !== -1) {
|
|
48
46
|
listeners.splice(index, 1);
|
|
49
47
|
if (listeners.length === 0) {
|
|
@@ -53,27 +51,29 @@ class EventEmitter {
|
|
|
53
51
|
this.events.set(event, listeners);
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
}
|
|
54
|
+
};
|
|
57
55
|
/**
|
|
58
56
|
* Registers a one-time event listener
|
|
59
57
|
*/
|
|
60
|
-
once(event, listener) {
|
|
61
|
-
|
|
58
|
+
EventEmitter.prototype.once = function (event, listener) {
|
|
59
|
+
var _this = this;
|
|
60
|
+
var onceWrapper = function (data) {
|
|
62
61
|
listener(data);
|
|
63
|
-
|
|
62
|
+
_this.off(event, onceWrapper);
|
|
64
63
|
};
|
|
65
64
|
this.on(event, onceWrapper);
|
|
66
|
-
}
|
|
65
|
+
};
|
|
67
66
|
/**
|
|
68
67
|
* Removes all listeners for an event or all events
|
|
69
68
|
*/
|
|
70
|
-
removeAllListeners(event) {
|
|
69
|
+
EventEmitter.prototype.removeAllListeners = function (event) {
|
|
71
70
|
if (event) {
|
|
72
71
|
this.events.delete(event);
|
|
73
72
|
}
|
|
74
73
|
else {
|
|
75
74
|
this.events.clear();
|
|
76
75
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
};
|
|
77
|
+
return EventEmitter;
|
|
78
|
+
}());
|
|
79
|
+
export { EventEmitter };
|
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Seed Phrase Utilities for Multi-Device Authentication
|
|
4
3
|
* Provides BIP39-compatible seed phrase generation and validation
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.seedToPassword = seedToPassword;
|
|
11
|
-
exports.deriveCredentialsFromMnemonic = deriveCredentialsFromMnemonic;
|
|
12
|
-
exports.formatSeedPhrase = formatSeedPhrase;
|
|
13
|
-
exports.normalizeSeedPhrase = normalizeSeedPhrase;
|
|
14
|
-
const bip39_1 = require("@scure/bip39");
|
|
15
|
-
const english_1 = require("@scure/bip39/wordlists/english");
|
|
16
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
17
|
-
const utils_1 = require("@noble/hashes/utils");
|
|
5
|
+
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic, } from "@scure/bip39";
|
|
6
|
+
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
7
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
8
|
+
import { bytesToHex } from "@noble/hashes/utils";
|
|
18
9
|
/**
|
|
19
10
|
* Generate a new 12-word BIP39 mnemonic seed phrase
|
|
20
11
|
* @returns {string} 12-word mnemonic seed phrase
|
|
21
12
|
*/
|
|
22
|
-
function generateSeedPhrase() {
|
|
23
|
-
return
|
|
13
|
+
export function generateSeedPhrase() {
|
|
14
|
+
return generateMnemonic(wordlist, 128); // 128 bits = 12 words
|
|
24
15
|
}
|
|
25
16
|
/**
|
|
26
17
|
* Validate a BIP39 mnemonic seed phrase
|
|
27
18
|
* @param {string} mnemonic - The seed phrase to validate
|
|
28
19
|
* @returns {boolean} True if valid, false otherwise
|
|
29
20
|
*/
|
|
30
|
-
function validateSeedPhrase(mnemonic) {
|
|
21
|
+
export function validateSeedPhrase(mnemonic) {
|
|
31
22
|
try {
|
|
32
|
-
return
|
|
23
|
+
return validateMnemonic(mnemonic, wordlist);
|
|
33
24
|
}
|
|
34
25
|
catch (error) {
|
|
35
26
|
return false;
|
|
@@ -41,24 +32,24 @@ function validateSeedPhrase(mnemonic) {
|
|
|
41
32
|
* @param {string} username - Username to include in derivation
|
|
42
33
|
* @returns {Uint8Array} 64-byte seed for key derivation
|
|
43
34
|
*/
|
|
44
|
-
function mnemonicToSeed(mnemonic, username) {
|
|
35
|
+
export function mnemonicToSeed(mnemonic, username) {
|
|
45
36
|
if (!validateSeedPhrase(mnemonic)) {
|
|
46
37
|
throw new Error("Invalid mnemonic seed phrase");
|
|
47
38
|
}
|
|
48
39
|
// Use username as additional entropy in the passphrase
|
|
49
40
|
// This ensures different users with same seed phrase get different keys
|
|
50
|
-
|
|
51
|
-
return
|
|
41
|
+
var passphrase = "shogun-".concat(username);
|
|
42
|
+
return mnemonicToSeedSync(mnemonic, passphrase);
|
|
52
43
|
}
|
|
53
44
|
/**
|
|
54
45
|
* Convert seed to deterministic password for GunDB
|
|
55
46
|
* @param {Uint8Array} seed - The seed from mnemonic
|
|
56
47
|
* @returns {string} Hex-encoded password
|
|
57
48
|
*/
|
|
58
|
-
function seedToPassword(seed) {
|
|
49
|
+
export function seedToPassword(seed) {
|
|
59
50
|
// Hash the seed to create a deterministic password
|
|
60
|
-
|
|
61
|
-
return
|
|
51
|
+
var hash = sha256(seed);
|
|
52
|
+
return bytesToHex(hash);
|
|
62
53
|
}
|
|
63
54
|
/**
|
|
64
55
|
* Derive GunDB credentials from mnemonic
|
|
@@ -66,12 +57,12 @@ function seedToPassword(seed) {
|
|
|
66
57
|
* @param {string} username - Username for derivation
|
|
67
58
|
* @returns {{password: string; seed: Uint8Array}} Credentials for GunDB
|
|
68
59
|
*/
|
|
69
|
-
function deriveCredentialsFromMnemonic(mnemonic, username) {
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
export function deriveCredentialsFromMnemonic(mnemonic, username) {
|
|
61
|
+
var seed = mnemonicToSeed(mnemonic, username);
|
|
62
|
+
var password = seedToPassword(seed);
|
|
72
63
|
return {
|
|
73
|
-
password,
|
|
74
|
-
seed,
|
|
64
|
+
password: password,
|
|
65
|
+
seed: seed,
|
|
75
66
|
};
|
|
76
67
|
}
|
|
77
68
|
/**
|
|
@@ -79,16 +70,16 @@ function deriveCredentialsFromMnemonic(mnemonic, username) {
|
|
|
79
70
|
* @param {string} mnemonic - The seed phrase
|
|
80
71
|
* @returns {string} Formatted seed phrase with numbers
|
|
81
72
|
*/
|
|
82
|
-
function formatSeedPhrase(mnemonic) {
|
|
83
|
-
|
|
84
|
-
return words.map((word, index)
|
|
73
|
+
export function formatSeedPhrase(mnemonic) {
|
|
74
|
+
var words = mnemonic.split(" ");
|
|
75
|
+
return words.map(function (word, index) { return "".concat(index + 1, ". ").concat(word); }).join("\n");
|
|
85
76
|
}
|
|
86
77
|
/**
|
|
87
78
|
* Normalize and clean user input for seed phrase
|
|
88
79
|
* @param {string} input - User-provided seed phrase
|
|
89
80
|
* @returns {string} Normalized seed phrase
|
|
90
81
|
*/
|
|
91
|
-
function normalizeSeedPhrase(input) {
|
|
82
|
+
export function normalizeSeedPhrase(input) {
|
|
92
83
|
return input
|
|
93
84
|
.toLowerCase()
|
|
94
85
|
.trim()
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Utility di validazione e generazione credenziali per ShogunCore
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.validateUsername = validateUsername;
|
|
5
|
-
exports.validateEmail = validateEmail;
|
|
6
|
-
exports.validateProvider = validateProvider;
|
|
7
|
-
exports.generateUsernameFromIdentity = generateUsernameFromIdentity;
|
|
8
|
-
exports.generateDeterministicPassword = generateDeterministicPassword;
|
|
9
2
|
// --- VALIDAZIONE ---
|
|
10
3
|
/**
|
|
11
4
|
* Valida uno username secondo le regole comuni
|
|
12
5
|
*/
|
|
13
|
-
function validateUsername(username) {
|
|
6
|
+
export function validateUsername(username) {
|
|
14
7
|
if (!username || typeof username !== "string")
|
|
15
8
|
return false;
|
|
16
9
|
if (username.length < 3 || username.length > 64)
|
|
@@ -22,7 +15,7 @@ function validateUsername(username) {
|
|
|
22
15
|
/**
|
|
23
16
|
* Valida una email
|
|
24
17
|
*/
|
|
25
|
-
function validateEmail(email) {
|
|
18
|
+
export function validateEmail(email) {
|
|
26
19
|
if (!email || typeof email !== "string")
|
|
27
20
|
return false;
|
|
28
21
|
// Regex semplice per email
|
|
@@ -32,7 +25,7 @@ function validateEmail(email) {
|
|
|
32
25
|
* Valida un provider OAuth supportato
|
|
33
26
|
* @deprecated OAuth has been removed from Shogun Core
|
|
34
27
|
*/
|
|
35
|
-
function validateProvider(provider) {
|
|
28
|
+
export function validateProvider(provider) {
|
|
36
29
|
console.warn("[validation] OAuth has been removed from Shogun Core");
|
|
37
30
|
return false;
|
|
38
31
|
}
|
|
@@ -41,37 +34,37 @@ function validateProvider(provider) {
|
|
|
41
34
|
* Genera uno username uniforme a partire da provider e userInfo
|
|
42
35
|
* Esempio: google_utente, github_12345, nostr_pubkey, web3_0xabc...
|
|
43
36
|
*/
|
|
44
|
-
function generateUsernameFromIdentity(provider, userInfo) {
|
|
37
|
+
export function generateUsernameFromIdentity(provider, userInfo) {
|
|
45
38
|
if (provider === "web3" && userInfo.id) {
|
|
46
|
-
return
|
|
39
|
+
return "web3_".concat(userInfo.id.toLowerCase());
|
|
47
40
|
}
|
|
48
41
|
if (provider === "nostr" && userInfo.id) {
|
|
49
|
-
return
|
|
42
|
+
return "nostr_".concat(userInfo.id);
|
|
50
43
|
}
|
|
51
44
|
if (provider === "webauthn" && userInfo.id) {
|
|
52
|
-
return
|
|
45
|
+
return "webauthn_".concat(userInfo.id);
|
|
53
46
|
}
|
|
54
47
|
if (userInfo.email && validateEmail(userInfo.email)) {
|
|
55
|
-
return
|
|
48
|
+
return "".concat(provider, "_").concat(userInfo.email.split("@")[0]);
|
|
56
49
|
}
|
|
57
50
|
if (userInfo.name) {
|
|
58
|
-
return
|
|
51
|
+
return "".concat(provider, "_").concat(userInfo.name.replace(/\s+/g, "_"));
|
|
59
52
|
}
|
|
60
53
|
if (userInfo.id) {
|
|
61
|
-
return
|
|
54
|
+
return "".concat(provider, "_").concat(userInfo.id);
|
|
62
55
|
}
|
|
63
|
-
return
|
|
56
|
+
return "".concat(provider, "_user");
|
|
64
57
|
}
|
|
65
58
|
// --- GENERAZIONE PASSWORD DETERMINISTICA ---
|
|
66
|
-
|
|
59
|
+
import { ethers } from "ethers";
|
|
67
60
|
/**
|
|
68
61
|
* Genera una password deterministica sicura a partire da un salt
|
|
69
62
|
* Usare per OAuth, Web3, Nostr, ecc.
|
|
70
63
|
*/
|
|
71
|
-
function generateDeterministicPassword(salt) {
|
|
64
|
+
export function generateDeterministicPassword(salt) {
|
|
72
65
|
try {
|
|
73
66
|
// Restituisce una stringa hex di 32 caratteri
|
|
74
|
-
return
|
|
67
|
+
return ethers.keccak256(ethers.toUtf8Bytes(salt)).slice(2, 34);
|
|
75
68
|
}
|
|
76
69
|
catch (error) {
|
|
77
70
|
// Fallback in case ethers is not available
|