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
package/dist/gundb/db.js
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* GunDB - Simplified database wrapper for Gun.js
|
|
4
|
-
* Provides only essential signup and login functionality
|
|
5
|
-
* Based on Gun.js User Authentication: https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
6
|
-
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.derive = exports.GunErrors = exports.crypto = exports.RxJS = exports.DataBase = void 0;
|
|
45
|
-
const rxjs_1 = require("./rxjs");
|
|
46
|
-
Object.defineProperty(exports, "RxJS", { enumerable: true, get: function () { return rxjs_1.RxJS; } });
|
|
47
|
-
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
48
|
-
const GunErrors = __importStar(require("./errors"));
|
|
49
|
-
exports.GunErrors = GunErrors;
|
|
50
|
-
const crypto = __importStar(require("./crypto"));
|
|
51
|
-
exports.crypto = crypto;
|
|
52
|
-
/**
|
|
53
|
-
* Configuration constants
|
|
54
|
-
*/
|
|
55
|
-
const CONFIG = {
|
|
56
|
-
PASSWORD: {
|
|
57
|
-
MIN_LENGTH: 8,
|
|
58
|
-
},
|
|
59
|
-
TIMEOUT: 30000, // 30 seconds
|
|
60
|
-
};
|
|
61
|
-
class DataBase {
|
|
62
|
-
constructor(gun, appScope = "shogun", core, sea) {
|
|
63
|
-
this.user = null;
|
|
64
|
-
this.onAuthCallbacks = [];
|
|
65
|
-
this._isDestroyed = false;
|
|
66
|
-
console.log("[DB] Initializing DataBase");
|
|
67
|
-
// Initialize event emitter
|
|
68
|
-
this.eventEmitter = new eventEmitter_1.EventEmitter();
|
|
69
|
-
// Validate Gun instance
|
|
70
|
-
if (!gun) {
|
|
71
|
-
throw new Error("Gun instance is required but was not provided");
|
|
72
|
-
}
|
|
73
|
-
if (typeof gun.user !== "function") {
|
|
74
|
-
throw new Error("Gun instance is invalid: gun.user is not a function");
|
|
75
|
-
}
|
|
76
|
-
this.gun = gun;
|
|
77
|
-
console.log("[DB] Gun instance validated");
|
|
78
|
-
// Recall user session if available
|
|
79
|
-
this.user = this.gun.user().recall({ sessionStorage: true });
|
|
80
|
-
console.log("[DB] User recall completed");
|
|
81
|
-
this.subscribeToAuthEvents();
|
|
82
|
-
console.log("[DB] Auth events subscribed");
|
|
83
|
-
this.crypto = crypto;
|
|
84
|
-
// Get SEA from gun instance or global
|
|
85
|
-
this.sea = sea || null;
|
|
86
|
-
if (!this.sea) {
|
|
87
|
-
if (this.gun.SEA) {
|
|
88
|
-
this.sea = this.gun.SEA;
|
|
89
|
-
}
|
|
90
|
-
else if (globalThis.Gun?.SEA) {
|
|
91
|
-
this.sea = globalThis.Gun.SEA;
|
|
92
|
-
}
|
|
93
|
-
else if (globalThis.SEA) {
|
|
94
|
-
this.sea = globalThis.SEA;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this._rxjs = new rxjs_1.RxJS(this.gun);
|
|
98
|
-
this.node = this.gun.get(appScope);
|
|
99
|
-
console.log("[DB] DataBase initialization completed");
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Initialize with app scope
|
|
103
|
-
*/
|
|
104
|
-
initialize(appScope = "shogun") {
|
|
105
|
-
console.log(`[DB] Initializing with appScope: ${appScope}`);
|
|
106
|
-
this.node = this.gun.get(appScope);
|
|
107
|
-
console.log("[DB] App scope node initialized");
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Subscribe to Gun auth events
|
|
111
|
-
*/
|
|
112
|
-
subscribeToAuthEvents() {
|
|
113
|
-
this.gun.on("auth", (ack) => {
|
|
114
|
-
if (ack.err) {
|
|
115
|
-
console.error("[DB] Auth event error:", ack.err);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
this.notifyAuthListeners(ack.sea?.pub || "");
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Notify all auth callbacks
|
|
124
|
-
*/
|
|
125
|
-
notifyAuthListeners(pub) {
|
|
126
|
-
const user = this.gun.user();
|
|
127
|
-
this.onAuthCallbacks.forEach((cb) => cb(user));
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Register authentication callback
|
|
131
|
-
*/
|
|
132
|
-
onAuth(callback) {
|
|
133
|
-
this.onAuthCallbacks.push(callback);
|
|
134
|
-
const user = this.gun.user();
|
|
135
|
-
if (user && user.is)
|
|
136
|
-
callback(user);
|
|
137
|
-
return () => {
|
|
138
|
-
const i = this.onAuthCallbacks.indexOf(callback);
|
|
139
|
-
if (i !== -1)
|
|
140
|
-
this.onAuthCallbacks.splice(i, 1);
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Check if user is logged in
|
|
145
|
-
*/
|
|
146
|
-
isLoggedIn() {
|
|
147
|
-
try {
|
|
148
|
-
const user = this.gun.user();
|
|
149
|
-
return !!(user && user.is && user.is.pub);
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Restore session from storage
|
|
157
|
-
*/
|
|
158
|
-
restoreSession() {
|
|
159
|
-
try {
|
|
160
|
-
if (typeof sessionStorage === "undefined") {
|
|
161
|
-
return { success: false, error: "sessionStorage not available" };
|
|
162
|
-
}
|
|
163
|
-
const sessionData = sessionStorage.getItem("gunSessionData");
|
|
164
|
-
if (!sessionData) {
|
|
165
|
-
return { success: false, error: "No saved session" };
|
|
166
|
-
}
|
|
167
|
-
const session = JSON.parse(sessionData);
|
|
168
|
-
if (!session.userPub) {
|
|
169
|
-
return { success: false, error: "Invalid session data" };
|
|
170
|
-
}
|
|
171
|
-
// Check if session is expired
|
|
172
|
-
if (session.expiresAt && Date.now() > session.expiresAt) {
|
|
173
|
-
sessionStorage.removeItem("gunSessionData");
|
|
174
|
-
return { success: false, error: "Session expired" };
|
|
175
|
-
}
|
|
176
|
-
// Verify session restoration
|
|
177
|
-
const user = this.gun.user();
|
|
178
|
-
if (user.is && user.is.pub === session.userPub) {
|
|
179
|
-
this.user = user;
|
|
180
|
-
return { success: true, userPub: session.userPub };
|
|
181
|
-
}
|
|
182
|
-
return { success: false, error: "Session verification failed" };
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
return { success: false, error: String(error) };
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Logout user
|
|
190
|
-
*/
|
|
191
|
-
logout() {
|
|
192
|
-
try {
|
|
193
|
-
const currentUser = this.gun.user();
|
|
194
|
-
if (currentUser && currentUser.is) {
|
|
195
|
-
currentUser.leave();
|
|
196
|
-
}
|
|
197
|
-
this.user = null;
|
|
198
|
-
if (typeof sessionStorage !== "undefined") {
|
|
199
|
-
sessionStorage.removeItem("gunSessionData");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
console.error("[DB] Error during logout:", error);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Validate password strength
|
|
208
|
-
*/
|
|
209
|
-
validatePasswordStrength(password) {
|
|
210
|
-
if (password.length < CONFIG.PASSWORD.MIN_LENGTH) {
|
|
211
|
-
return {
|
|
212
|
-
valid: false,
|
|
213
|
-
error: `Password must be at least ${CONFIG.PASSWORD.MIN_LENGTH} characters long`,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
return { valid: true };
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Validate signup credentials
|
|
220
|
-
*/
|
|
221
|
-
validateSignupCredentials(username, password, pair) {
|
|
222
|
-
if (!username || username.length < 1) {
|
|
223
|
-
return {
|
|
224
|
-
valid: false,
|
|
225
|
-
error: "Username must be more than 0 characters long",
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
if (!/^[a-zA-Z0-9._-]+$/.test(username)) {
|
|
229
|
-
return {
|
|
230
|
-
valid: false,
|
|
231
|
-
error: "Username can only contain letters, numbers, dots, underscores, and hyphens",
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
if (pair) {
|
|
235
|
-
if (!pair.pub || !pair.priv || !pair.epub || !pair.epriv) {
|
|
236
|
-
return { valid: false, error: "Invalid pair provided" };
|
|
237
|
-
}
|
|
238
|
-
return { valid: true };
|
|
239
|
-
}
|
|
240
|
-
return this.validatePasswordStrength(password);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Reset authentication state
|
|
244
|
-
*/
|
|
245
|
-
resetAuthState() {
|
|
246
|
-
try {
|
|
247
|
-
const user = this.gun.user();
|
|
248
|
-
if (user && user._) {
|
|
249
|
-
const cat = user._;
|
|
250
|
-
// Reset Gun's internal auth state
|
|
251
|
-
cat.ing = false;
|
|
252
|
-
cat.auth = null;
|
|
253
|
-
cat.act = null;
|
|
254
|
-
}
|
|
255
|
-
user.leave();
|
|
256
|
-
this.user = null;
|
|
257
|
-
}
|
|
258
|
-
catch (e) {
|
|
259
|
-
// Ignore
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Build login result
|
|
264
|
-
*/
|
|
265
|
-
buildLoginResult(username, userPub) {
|
|
266
|
-
const seaPair = this.gun.user()?._?.sea;
|
|
267
|
-
return {
|
|
268
|
-
success: true,
|
|
269
|
-
userPub,
|
|
270
|
-
username,
|
|
271
|
-
sea: seaPair
|
|
272
|
-
? {
|
|
273
|
-
pub: seaPair.pub,
|
|
274
|
-
priv: seaPair.priv,
|
|
275
|
-
epub: seaPair.epub,
|
|
276
|
-
epriv: seaPair.epriv,
|
|
277
|
-
}
|
|
278
|
-
: undefined,
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Save credentials to session storage
|
|
283
|
-
*/
|
|
284
|
-
saveCredentials(userInfo) {
|
|
285
|
-
try {
|
|
286
|
-
if (typeof sessionStorage !== "undefined") {
|
|
287
|
-
const sessionInfo = {
|
|
288
|
-
username: userInfo.alias,
|
|
289
|
-
pair: userInfo.pair,
|
|
290
|
-
userPub: userInfo.userPub,
|
|
291
|
-
timestamp: Date.now(),
|
|
292
|
-
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
293
|
-
};
|
|
294
|
-
sessionStorage.setItem("gunSessionData", JSON.stringify(sessionInfo));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
console.error("[DB] Error saving credentials:", error);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Sign up a new user
|
|
303
|
-
* Based on Gun.js user().create() - https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
304
|
-
*/
|
|
305
|
-
async signUp(username, password, pair) {
|
|
306
|
-
const validation = this.validateSignupCredentials(username, password, pair);
|
|
307
|
-
if (!validation.valid) {
|
|
308
|
-
return { success: false, error: validation.error };
|
|
309
|
-
}
|
|
310
|
-
this.resetAuthState();
|
|
311
|
-
const normalizedUsername = username.trim().toLowerCase();
|
|
312
|
-
return new Promise((resolve) => {
|
|
313
|
-
const timeoutId = setTimeout(() => {
|
|
314
|
-
this.resetAuthState();
|
|
315
|
-
resolve({ success: false, error: "Signup timeout" });
|
|
316
|
-
}, CONFIG.TIMEOUT);
|
|
317
|
-
const callback = (ack) => {
|
|
318
|
-
clearTimeout(timeoutId);
|
|
319
|
-
if (ack.err) {
|
|
320
|
-
this.resetAuthState();
|
|
321
|
-
resolve({ success: false, error: ack.err });
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
const user = this.gun.user();
|
|
325
|
-
const userPub = user?.is?.pub;
|
|
326
|
-
if (!userPub) {
|
|
327
|
-
this.resetAuthState();
|
|
328
|
-
resolve({ success: false, error: "No userPub available" });
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
this.user = user;
|
|
332
|
-
const sea = user?._?.sea;
|
|
333
|
-
resolve({
|
|
334
|
-
success: true,
|
|
335
|
-
userPub,
|
|
336
|
-
username: normalizedUsername,
|
|
337
|
-
isNewUser: true,
|
|
338
|
-
sea: sea
|
|
339
|
-
? {
|
|
340
|
-
pub: sea.pub,
|
|
341
|
-
priv: sea.priv,
|
|
342
|
-
epub: sea.epub,
|
|
343
|
-
epriv: sea.epriv,
|
|
344
|
-
}
|
|
345
|
-
: undefined,
|
|
346
|
-
});
|
|
347
|
-
};
|
|
348
|
-
if (pair) {
|
|
349
|
-
this.gun.user().auth(pair, callback);
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
this.gun.user().create(normalizedUsername, password, callback);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Login with username and password
|
|
358
|
-
* Based on Gun.js user().auth() - https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
359
|
-
*/
|
|
360
|
-
async login(username, password, pair) {
|
|
361
|
-
this.resetAuthState();
|
|
362
|
-
const normalizedUsername = username.trim().toLowerCase();
|
|
363
|
-
return new Promise((resolve) => {
|
|
364
|
-
const timeoutId = setTimeout(() => {
|
|
365
|
-
this.resetAuthState();
|
|
366
|
-
resolve({ success: false, error: "Login timeout" });
|
|
367
|
-
}, CONFIG.TIMEOUT);
|
|
368
|
-
const callback = (ack) => {
|
|
369
|
-
clearTimeout(timeoutId);
|
|
370
|
-
if (ack.err) {
|
|
371
|
-
this.resetAuthState();
|
|
372
|
-
resolve({ success: false, error: ack.err });
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
const user = this.gun.user();
|
|
376
|
-
const userPub = user?.is?.pub;
|
|
377
|
-
if (!userPub) {
|
|
378
|
-
this.resetAuthState();
|
|
379
|
-
resolve({ success: false, error: "No userPub available" });
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
this.user = user;
|
|
383
|
-
const alias = user?.is?.alias;
|
|
384
|
-
const userPair = user?._?.sea;
|
|
385
|
-
try {
|
|
386
|
-
this.saveCredentials({
|
|
387
|
-
alias: alias || normalizedUsername,
|
|
388
|
-
pair: pair ?? userPair,
|
|
389
|
-
userPub: userPub,
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
catch (saveError) {
|
|
393
|
-
// Ignore save errors
|
|
394
|
-
}
|
|
395
|
-
resolve(this.buildLoginResult(alias || normalizedUsername, userPub));
|
|
396
|
-
};
|
|
397
|
-
if (pair) {
|
|
398
|
-
this.gun.user().auth(pair, callback);
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
this.gun.user().auth(normalizedUsername, password, callback);
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Get current user
|
|
407
|
-
*/
|
|
408
|
-
getCurrentUser() {
|
|
409
|
-
try {
|
|
410
|
-
const user = this.gun.user();
|
|
411
|
-
if (user && user.is && user.is.pub) {
|
|
412
|
-
return {
|
|
413
|
-
pub: user.is.pub,
|
|
414
|
-
user: user,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
return null;
|
|
418
|
-
}
|
|
419
|
-
catch (error) {
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Login with SEA pair
|
|
425
|
-
*/
|
|
426
|
-
async loginWithPair(username, pair) {
|
|
427
|
-
return this.login(username, "", pair);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Get RxJS module
|
|
431
|
-
*/
|
|
432
|
-
rx() {
|
|
433
|
-
return this._rxjs;
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Destroy database instance
|
|
437
|
-
*/
|
|
438
|
-
destroy() {
|
|
439
|
-
if (this._isDestroyed)
|
|
440
|
-
return;
|
|
441
|
-
console.log("[DB] Destroying DataBase instance...");
|
|
442
|
-
this._isDestroyed = true;
|
|
443
|
-
this.onAuthCallbacks.length = 0;
|
|
444
|
-
// Clear event listeners
|
|
445
|
-
this.eventEmitter.removeAllListeners();
|
|
446
|
-
if (this.user) {
|
|
447
|
-
try {
|
|
448
|
-
this.user.leave();
|
|
449
|
-
}
|
|
450
|
-
catch (error) {
|
|
451
|
-
// Ignore
|
|
452
|
-
}
|
|
453
|
-
this.user = null;
|
|
454
|
-
}
|
|
455
|
-
this._rxjs = undefined;
|
|
456
|
-
console.log("[DB] DataBase instance destroyed");
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Aggressive auth cleanup (kept for compatibility with tests)
|
|
460
|
-
*/
|
|
461
|
-
aggressiveAuthCleanup() {
|
|
462
|
-
console.log("🧹 Performing aggressive auth cleanup...");
|
|
463
|
-
this.resetAuthState();
|
|
464
|
-
this.logout();
|
|
465
|
-
console.log("✓ Aggressive auth cleanup completed");
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Event emitter methods for CoreInitializer compatibility
|
|
469
|
-
*/
|
|
470
|
-
on(event, listener) {
|
|
471
|
-
this.eventEmitter.on(event, listener);
|
|
472
|
-
}
|
|
473
|
-
off(event, listener) {
|
|
474
|
-
this.eventEmitter.off(event, listener);
|
|
475
|
-
}
|
|
476
|
-
once(event, listener) {
|
|
477
|
-
this.eventEmitter.once(event, listener);
|
|
478
|
-
}
|
|
479
|
-
emit(event, data) {
|
|
480
|
-
return this.eventEmitter.emit(event, data);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
exports.DataBase = DataBase;
|
|
484
|
-
var derive_1 = require("./derive");
|
|
485
|
-
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return __importDefault(derive_1).default; } });
|