shogun-core 5.2.0 → 5.2.1
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_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/shogun-core.js +160386 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +236 -0
- package/dist/core.js +329 -0
- package/dist/crypto/asymmetric.js +99 -0
- package/dist/crypto/double-ratchet.js +370 -0
- package/dist/crypto/file-encryption.js +213 -0
- package/dist/crypto/hashing.js +87 -0
- package/dist/crypto/index.js +34 -0
- package/dist/crypto/mls-codec.js +202 -0
- package/dist/crypto/mls.js +550 -0
- package/dist/crypto/pgp.js +390 -0
- package/dist/crypto/random-generation.js +341 -0
- package/dist/crypto/sframe.js +350 -0
- package/dist/crypto/signal-protocol.js +376 -0
- package/dist/crypto/symmetric.js +91 -0
- package/dist/crypto/types.js +2 -0
- package/dist/crypto/utils.js +140 -0
- package/dist/examples/auth-test.js +253 -0
- package/dist/examples/crypto-identity-example.js +151 -0
- package/dist/examples/crypto-working-test.js +83 -0
- package/dist/examples/double-ratchet-test.js +155 -0
- package/dist/examples/mls-advanced-example.js +294 -0
- package/dist/examples/mls-sframe-test.js +304 -0
- package/dist/examples/pgp-example.js +200 -0
- package/dist/examples/quick-auth-test.js +61 -0
- package/dist/examples/random-generation-test.js +151 -0
- package/dist/examples/signal-protocol-test.js +38 -0
- package/dist/examples/simple-api-test.js +114 -0
- package/dist/examples/simple-crypto-identity-example.js +84 -0
- package/dist/examples/timeout-test.js +227 -0
- package/dist/examples/zkproof-credentials-example.js +212 -0
- package/dist/examples/zkproof-example.js +201 -0
- package/dist/gundb/api.js +435 -0
- package/dist/gundb/crypto.js +283 -0
- package/dist/gundb/db.js +1946 -0
- package/dist/gundb/derive.js +232 -0
- package/dist/gundb/errors.js +76 -0
- package/dist/gundb/index.js +22 -0
- package/dist/gundb/rxjs.js +447 -0
- package/dist/gundb/types.js +5 -0
- package/dist/index.js +58 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/interfaces/events.js +40 -0
- package/dist/interfaces/plugin.js +2 -0
- package/dist/interfaces/shogun.js +37 -0
- package/dist/managers/AuthManager.js +226 -0
- package/dist/managers/CoreInitializer.js +228 -0
- package/dist/managers/CryptoIdentityManager.js +366 -0
- package/dist/managers/EventManager.js +70 -0
- package/dist/managers/PluginManager.js +299 -0
- package/dist/plugins/base.js +50 -0
- package/dist/plugins/index.js +32 -0
- package/dist/plugins/nostr/index.js +20 -0
- package/dist/plugins/nostr/nostrConnector.js +419 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
- package/dist/plugins/nostr/nostrSigner.js +319 -0
- package/dist/plugins/nostr/types.js +2 -0
- package/dist/plugins/smartwallet/index.js +18 -0
- package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
- package/dist/plugins/smartwallet/types.js +2 -0
- package/dist/plugins/web3/index.js +20 -0
- package/dist/plugins/web3/types.js +2 -0
- package/dist/plugins/web3/web3Connector.js +533 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
- package/dist/plugins/web3/web3Signer.js +314 -0
- package/dist/plugins/webauthn/index.js +19 -0
- package/dist/plugins/webauthn/types.js +14 -0
- package/dist/plugins/webauthn/webauthn.js +496 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
- package/dist/plugins/webauthn/webauthnSigner.js +310 -0
- package/dist/plugins/zkproof/index.js +53 -0
- package/dist/plugins/zkproof/types.js +2 -0
- package/dist/plugins/zkproof/zkCredentials.js +213 -0
- package/dist/plugins/zkproof/zkProofConnector.js +198 -0
- package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
- package/dist/storage/storage.js +145 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/crypto/asymmetric.d.ts +6 -0
- package/dist/types/crypto/double-ratchet.d.ts +22 -0
- package/dist/types/crypto/file-encryption.d.ts +19 -0
- package/dist/types/crypto/hashing.d.ts +9 -0
- package/dist/types/crypto/index.d.ts +13 -0
- package/dist/types/crypto/mls-codec.d.ts +39 -0
- package/dist/types/crypto/mls.d.ts +130 -0
- package/dist/types/crypto/pgp.d.ts +95 -0
- package/dist/types/crypto/random-generation.d.ts +35 -0
- package/dist/types/crypto/sframe.d.ts +102 -0
- package/dist/types/crypto/signal-protocol.d.ts +26 -0
- package/dist/types/crypto/symmetric.d.ts +9 -0
- package/dist/types/crypto/types.d.ts +144 -0
- package/dist/types/crypto/utils.d.ts +22 -0
- package/dist/types/examples/auth-test.d.ts +8 -0
- package/dist/types/examples/crypto-identity-example.d.ts +5 -0
- package/dist/types/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/examples/mls-advanced-example.d.ts +53 -0
- package/dist/types/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/examples/pgp-example.d.ts +75 -0
- package/dist/types/examples/quick-auth-test.d.ts +8 -0
- package/dist/types/examples/random-generation-test.d.ts +1 -0
- package/dist/types/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/examples/simple-api-test.d.ts +10 -0
- package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
- package/dist/types/examples/timeout-test.d.ts +8 -0
- package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- package/dist/types/gundb/api.d.ts +185 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +397 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/types.d.ts +255 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +208 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +18 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/smartwallet/index.d.ts +2 -0
- package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
- package/dist/types/plugins/smartwallet/types.d.ts +80 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +183 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/plugins/zkproof/index.d.ts +48 -0
- package/dist/types/plugins/zkproof/types.d.ts +123 -0
- package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
- package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
- package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
- package/dist/types/storage/storage.d.ts +51 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/seedPhrase.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +246 -0
- package/dist/utils/eventEmitter.js +79 -0
- package/dist/utils/seedPhrase.js +97 -0
- package/dist/utils/validation.js +81 -0
- package/package.json +10 -1
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simplified configuration options to reduce complexity
|
|
4
|
+
* Provides sensible defaults and easy-to-use presets
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.QuickConfig = exports.ConfigHelpers = exports.ShogunConfigBuilder = exports.ShogunPresets = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Preset configurations for common use cases
|
|
10
|
+
*/
|
|
11
|
+
exports.ShogunPresets = {
|
|
12
|
+
/**
|
|
13
|
+
* Minimal configuration for simple apps
|
|
14
|
+
*/
|
|
15
|
+
minimal: () => ({
|
|
16
|
+
gunOptions: {
|
|
17
|
+
peers: ["https://relay.shogun-eco.xyz/gun"],
|
|
18
|
+
localStorage: true,
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
/**
|
|
22
|
+
* Development configuration with local storage
|
|
23
|
+
*/
|
|
24
|
+
development: () => ({
|
|
25
|
+
gunOptions: {
|
|
26
|
+
peers: ["https://relay.shogun-eco.xyz/gun"],
|
|
27
|
+
localStorage: true,
|
|
28
|
+
radisk: false,
|
|
29
|
+
},
|
|
30
|
+
timeouts: {
|
|
31
|
+
login: 5000,
|
|
32
|
+
signup: 5000,
|
|
33
|
+
operation: 3000,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
/**
|
|
37
|
+
* Production configuration with multiple peers
|
|
38
|
+
*/
|
|
39
|
+
production: (customPeers) => ({
|
|
40
|
+
gunOptions: {
|
|
41
|
+
peers: customPeers || [
|
|
42
|
+
"https://relay.shogun-eco.xyz/gun",
|
|
43
|
+
"https://peer.wallie.io/gun",
|
|
44
|
+
],
|
|
45
|
+
localStorage: true,
|
|
46
|
+
radisk: true,
|
|
47
|
+
},
|
|
48
|
+
timeouts: {
|
|
49
|
+
login: 10000,
|
|
50
|
+
signup: 10000,
|
|
51
|
+
operation: 5000,
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
/**
|
|
55
|
+
* Offline-first configuration
|
|
56
|
+
*/
|
|
57
|
+
offline: () => ({
|
|
58
|
+
gunOptions: {
|
|
59
|
+
peers: [],
|
|
60
|
+
localStorage: true,
|
|
61
|
+
radisk: true,
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
/**
|
|
65
|
+
* Web3-enabled configuration
|
|
66
|
+
*/
|
|
67
|
+
web3: () => ({
|
|
68
|
+
gunOptions: {
|
|
69
|
+
peers: ["https://relay.shogun-eco.xyz/gun"],
|
|
70
|
+
localStorage: true,
|
|
71
|
+
},
|
|
72
|
+
web3: {
|
|
73
|
+
enabled: true,
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
/**
|
|
77
|
+
* WebAuthn-enabled configuration
|
|
78
|
+
*/
|
|
79
|
+
webauthn: () => ({
|
|
80
|
+
gunOptions: {
|
|
81
|
+
peers: ["https://relay.shogun-eco.xyz/gun"],
|
|
82
|
+
localStorage: true,
|
|
83
|
+
},
|
|
84
|
+
webauthn: {
|
|
85
|
+
enabled: true,
|
|
86
|
+
rpName: "My Shogun App",
|
|
87
|
+
rpId: window.location.hostname,
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Configuration builder for custom setups
|
|
93
|
+
*/
|
|
94
|
+
class ShogunConfigBuilder {
|
|
95
|
+
constructor() {
|
|
96
|
+
this.config = {};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Set Gun options
|
|
100
|
+
*/
|
|
101
|
+
gunOptions(options) {
|
|
102
|
+
this.config.gunOptions = { ...this.config.gunOptions, ...options };
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Add peers
|
|
107
|
+
*/
|
|
108
|
+
peers(peerList) {
|
|
109
|
+
this.config.gunOptions = {
|
|
110
|
+
...this.config.gunOptions,
|
|
111
|
+
peers: [...(this.config.gunOptions?.peers || []), ...peerList],
|
|
112
|
+
};
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Enable WebAuthn
|
|
117
|
+
*/
|
|
118
|
+
enableWebAuthn(rpName, rpId) {
|
|
119
|
+
this.config.webauthn = {
|
|
120
|
+
enabled: true,
|
|
121
|
+
rpName: rpName || "My App",
|
|
122
|
+
rpId: rpId || window.location.hostname,
|
|
123
|
+
};
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Enable Web3
|
|
128
|
+
*/
|
|
129
|
+
enableWeb3() {
|
|
130
|
+
this.config.web3 = { enabled: true };
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Enable Nostr
|
|
135
|
+
*/
|
|
136
|
+
enableNostr() {
|
|
137
|
+
this.config.nostr = { enabled: true };
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Set timeouts
|
|
142
|
+
*/
|
|
143
|
+
timeouts(timeouts) {
|
|
144
|
+
this.config.timeouts = { ...this.config.timeouts, ...timeouts };
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build the final configuration
|
|
149
|
+
*/
|
|
150
|
+
build() {
|
|
151
|
+
return this.config;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.ShogunConfigBuilder = ShogunConfigBuilder;
|
|
155
|
+
/**
|
|
156
|
+
* Helper functions for common configuration patterns
|
|
157
|
+
*/
|
|
158
|
+
exports.ConfigHelpers = {
|
|
159
|
+
/**
|
|
160
|
+
* Create a configuration for a specific environment
|
|
161
|
+
*/
|
|
162
|
+
forEnvironment(env) {
|
|
163
|
+
switch (env) {
|
|
164
|
+
case "development":
|
|
165
|
+
return exports.ShogunPresets.development();
|
|
166
|
+
case "production":
|
|
167
|
+
return exports.ShogunPresets.production();
|
|
168
|
+
case "test":
|
|
169
|
+
return exports.ShogunPresets.offline();
|
|
170
|
+
default:
|
|
171
|
+
return exports.ShogunPresets.minimal();
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
/**
|
|
175
|
+
* Create a configuration with custom peers
|
|
176
|
+
*/
|
|
177
|
+
withPeers(peers) {
|
|
178
|
+
return exports.ShogunPresets.production(peers);
|
|
179
|
+
},
|
|
180
|
+
/**
|
|
181
|
+
* Create a configuration for a specific use case
|
|
182
|
+
*/
|
|
183
|
+
forUseCase(useCase) {
|
|
184
|
+
const baseConfig = exports.ShogunPresets.production();
|
|
185
|
+
switch (useCase) {
|
|
186
|
+
case "chat":
|
|
187
|
+
return {
|
|
188
|
+
...baseConfig,
|
|
189
|
+
timeouts: { ...baseConfig.timeouts, operation: 2000 },
|
|
190
|
+
};
|
|
191
|
+
case "social":
|
|
192
|
+
return {
|
|
193
|
+
...baseConfig,
|
|
194
|
+
webauthn: { enabled: true, rpName: "Social App" },
|
|
195
|
+
};
|
|
196
|
+
case "gaming":
|
|
197
|
+
return {
|
|
198
|
+
...baseConfig,
|
|
199
|
+
timeouts: { ...baseConfig.timeouts, operation: 1000 },
|
|
200
|
+
};
|
|
201
|
+
case "finance":
|
|
202
|
+
return {
|
|
203
|
+
...baseConfig,
|
|
204
|
+
webauthn: { enabled: true, rpName: "Finance App" },
|
|
205
|
+
timeouts: { ...baseConfig.timeouts, login: 15000 },
|
|
206
|
+
};
|
|
207
|
+
default:
|
|
208
|
+
return baseConfig;
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Quick configuration functions
|
|
214
|
+
*/
|
|
215
|
+
exports.QuickConfig = {
|
|
216
|
+
/**
|
|
217
|
+
* Minimal setup for quick testing
|
|
218
|
+
*/
|
|
219
|
+
test: () => exports.ShogunPresets.minimal(),
|
|
220
|
+
/**
|
|
221
|
+
* Standard setup for most apps
|
|
222
|
+
*/
|
|
223
|
+
standard: () => exports.ShogunPresets.production(),
|
|
224
|
+
/**
|
|
225
|
+
* Setup with WebAuthn for secure apps
|
|
226
|
+
*/
|
|
227
|
+
secure: () => exports.ShogunPresets.webauthn(),
|
|
228
|
+
/**
|
|
229
|
+
* Setup with Web3 for crypto apps
|
|
230
|
+
*/
|
|
231
|
+
crypto: () => exports.ShogunPresets.web3(),
|
|
232
|
+
/**
|
|
233
|
+
* Offline setup for local development
|
|
234
|
+
*/
|
|
235
|
+
local: () => exports.ShogunPresets.offline(),
|
|
236
|
+
};
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShogunCore = void 0;
|
|
4
|
+
const errorHandler_1 = require("./utils/errorHandler");
|
|
5
|
+
// Import managers
|
|
6
|
+
const PluginManager_1 = require("./managers/PluginManager");
|
|
7
|
+
const AuthManager_1 = require("./managers/AuthManager");
|
|
8
|
+
const EventManager_1 = require("./managers/EventManager");
|
|
9
|
+
const CoreInitializer_1 = require("./managers/CoreInitializer");
|
|
10
|
+
/**
|
|
11
|
+
* Main ShogunCore class - implements the IShogunCore interface
|
|
12
|
+
*
|
|
13
|
+
* This is the primary entry point for the Shogun SDK, providing access to:
|
|
14
|
+
* - Decentralized database (GunInstance)
|
|
15
|
+
* - Authentication methods (traditional, WebAuthn, MetaMask)
|
|
16
|
+
* - Plugin system for extensibility
|
|
17
|
+
* - RxJS integration for reactive programming
|
|
18
|
+
*
|
|
19
|
+
* @since 2.0.0
|
|
20
|
+
*/
|
|
21
|
+
class ShogunCore {
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the Shogun SDK
|
|
24
|
+
* @param config - SDK Configuration object
|
|
25
|
+
* @description Creates a new instance of ShogunCore with the provided configuration.
|
|
26
|
+
* Initializes all required components including storage, event emitter, GunInstance connection,
|
|
27
|
+
* and plugin system.
|
|
28
|
+
*/
|
|
29
|
+
constructor(config) {
|
|
30
|
+
this._user = null;
|
|
31
|
+
this.config = config;
|
|
32
|
+
// Initialize managers
|
|
33
|
+
this.eventManager = new EventManager_1.EventManager();
|
|
34
|
+
this.pluginManager = new PluginManager_1.PluginManager(this);
|
|
35
|
+
this.authManager = new AuthManager_1.AuthManager(this);
|
|
36
|
+
this.coreInitializer = new CoreInitializer_1.CoreInitializer(this);
|
|
37
|
+
// Initialize async components
|
|
38
|
+
this.coreInitializer.initialize(config).catch((error) => {
|
|
39
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
40
|
+
console.warn("Error during async initialization:", error);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Access to the Gun instance
|
|
46
|
+
* @returns The Gun instance
|
|
47
|
+
*/
|
|
48
|
+
get gun() {
|
|
49
|
+
return this._gun;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Access to the current user
|
|
53
|
+
* @returns The current Gun user instance
|
|
54
|
+
*/
|
|
55
|
+
get user() {
|
|
56
|
+
return this._user;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets the current user information
|
|
60
|
+
* @returns Current user object or null
|
|
61
|
+
*/
|
|
62
|
+
getCurrentUser() {
|
|
63
|
+
if (!this.db) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return this.db.getCurrentUser();
|
|
67
|
+
}
|
|
68
|
+
// *********************************************************************************************************
|
|
69
|
+
// 🔌 PLUGIN MANAGEMENT 🔌
|
|
70
|
+
// *********************************************************************************************************
|
|
71
|
+
/**
|
|
72
|
+
* Registers a plugin with the Shogun SDK
|
|
73
|
+
* @param plugin Plugin instance to register
|
|
74
|
+
* @throws Error if a plugin with the same name is already registered
|
|
75
|
+
*/
|
|
76
|
+
register(plugin) {
|
|
77
|
+
this.pluginManager.register(plugin);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Unregisters a plugin from the Shogun SDK
|
|
81
|
+
* @param pluginName Name of the plugin to unregister
|
|
82
|
+
*/
|
|
83
|
+
unregister(pluginName) {
|
|
84
|
+
this.pluginManager.unregister(pluginName);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve a registered plugin by name
|
|
88
|
+
* @param name Name of the plugin
|
|
89
|
+
* @returns The requested plugin or undefined if not found
|
|
90
|
+
* @template T Type of the plugin or its public interface
|
|
91
|
+
*/
|
|
92
|
+
getPlugin(name) {
|
|
93
|
+
return this.pluginManager.getPlugin(name);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get information about all registered plugins
|
|
97
|
+
* @returns Array of plugin information objects
|
|
98
|
+
*/
|
|
99
|
+
getPluginsInfo() {
|
|
100
|
+
return this.pluginManager.getPluginsInfo();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the total number of registered plugins
|
|
104
|
+
* @returns Number of registered plugins
|
|
105
|
+
*/
|
|
106
|
+
getPluginCount() {
|
|
107
|
+
return this.pluginManager.getPluginCount();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Check if all plugins are properly initialized
|
|
111
|
+
* @returns Object with initialization status for each plugin
|
|
112
|
+
*/
|
|
113
|
+
getPluginsInitializationStatus() {
|
|
114
|
+
return this.pluginManager.getPluginsInitializationStatus();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Validate plugin system integrity
|
|
118
|
+
* @returns Object with validation results
|
|
119
|
+
*/
|
|
120
|
+
validatePluginSystem() {
|
|
121
|
+
return this.pluginManager.validatePluginSystem();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Attempt to reinitialize failed plugins
|
|
125
|
+
* @returns Object with reinitialization results
|
|
126
|
+
*/
|
|
127
|
+
reinitializeFailedPlugins() {
|
|
128
|
+
return this.pluginManager.reinitializeFailedPlugins();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check plugin compatibility with current ShogunCore version
|
|
132
|
+
* @returns Object with compatibility information
|
|
133
|
+
*/
|
|
134
|
+
checkPluginCompatibility() {
|
|
135
|
+
return this.pluginManager.checkPluginCompatibility();
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get comprehensive debug information about the plugin system
|
|
139
|
+
* @returns Complete plugin system debug information
|
|
140
|
+
*/
|
|
141
|
+
getPluginSystemDebugInfo() {
|
|
142
|
+
return this.pluginManager.getPluginSystemDebugInfo();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if a plugin is registered
|
|
146
|
+
* @param name Name of the plugin to check
|
|
147
|
+
* @returns true if the plugin is registered, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
hasPlugin(name) {
|
|
150
|
+
return this.pluginManager.hasPlugin(name);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get all plugins of a specific category
|
|
154
|
+
* @param category Category of plugins to filter
|
|
155
|
+
* @returns Array of plugins in the specified category
|
|
156
|
+
*/
|
|
157
|
+
getPluginsByCategory(category) {
|
|
158
|
+
return this.pluginManager.getPluginsByCategory(category);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get an authentication method plugin by type
|
|
162
|
+
* @param type The type of authentication method
|
|
163
|
+
* @returns The authentication plugin or undefined if not available
|
|
164
|
+
* This is a more modern approach to accessing authentication methods
|
|
165
|
+
*/
|
|
166
|
+
getAuthenticationMethod(type) {
|
|
167
|
+
return this.authManager.getAuthenticationMethod(type);
|
|
168
|
+
}
|
|
169
|
+
// *********************************************************************************************************
|
|
170
|
+
// 🔐 ERROR HANDLER 🔐
|
|
171
|
+
// *********************************************************************************************************
|
|
172
|
+
/**
|
|
173
|
+
* Retrieve recent errors logged by the system
|
|
174
|
+
* @param count - Number of errors to retrieve (default: 10)
|
|
175
|
+
* @returns List of most recent errors
|
|
176
|
+
*/
|
|
177
|
+
getRecentErrors(count = 10) {
|
|
178
|
+
return errorHandler_1.ErrorHandler.getRecentErrors(count);
|
|
179
|
+
}
|
|
180
|
+
// *********************************************************************************************************
|
|
181
|
+
// 🔐 AUTHENTICATION
|
|
182
|
+
// *********************************************************************************************************
|
|
183
|
+
/**
|
|
184
|
+
* Check if user is logged in
|
|
185
|
+
* @returns {boolean} True if user is logged in, false otherwise
|
|
186
|
+
* @description Verifies authentication status by checking GunInstance login state
|
|
187
|
+
* and presence of authentication credentials in storage
|
|
188
|
+
*/
|
|
189
|
+
isLoggedIn() {
|
|
190
|
+
return this.authManager.isLoggedIn();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Perform user logout
|
|
194
|
+
* @description Logs out the current user from GunInstance and emits logout event.
|
|
195
|
+
* If user is not authenticated, the logout operation is ignored.
|
|
196
|
+
*/
|
|
197
|
+
logout() {
|
|
198
|
+
this.authManager.logout();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Authenticate user with username and password
|
|
202
|
+
* @param username - Username
|
|
203
|
+
* @param password - User password
|
|
204
|
+
* @returns {Promise<AuthResult>} Promise with authentication result
|
|
205
|
+
* @description Attempts to log in user with provided credentials.
|
|
206
|
+
* Emits login event on success.
|
|
207
|
+
*/
|
|
208
|
+
async login(username, password, pair) {
|
|
209
|
+
return this.authManager.login(username, password, pair);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Login with GunDB pair directly
|
|
213
|
+
* @param pair - GunDB SEA pair for authentication
|
|
214
|
+
* @returns {Promise<AuthResult>} Promise with authentication result
|
|
215
|
+
* @description Authenticates user using a GunDB pair directly.
|
|
216
|
+
* Emits login event on success.
|
|
217
|
+
*/
|
|
218
|
+
async loginWithPair(username, pair) {
|
|
219
|
+
return this.authManager.loginWithPair(username, pair);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Register a new user with provided credentials
|
|
223
|
+
* @param username - Username
|
|
224
|
+
* @param password - Password
|
|
225
|
+
* @param email - Email (optional)
|
|
226
|
+
* @param pair - Pair of keys
|
|
227
|
+
* @returns {Promise<SignUpResult>} Registration result
|
|
228
|
+
* @description Creates a new user account with the provided credentials.
|
|
229
|
+
* Validates password requirements and emits signup event on success.
|
|
230
|
+
*/
|
|
231
|
+
async signUp(username, password, pair) {
|
|
232
|
+
return this.authManager.signUp(username, password, pair);
|
|
233
|
+
}
|
|
234
|
+
// 📢 EVENT EMITTER 📢
|
|
235
|
+
/**
|
|
236
|
+
* Emits an event through the core's event emitter.
|
|
237
|
+
* Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
|
|
238
|
+
* @param eventName The name of the event to emit.
|
|
239
|
+
* @param data The data to pass with the event.
|
|
240
|
+
* @returns {boolean} Indicates if the event had listeners.
|
|
241
|
+
*/
|
|
242
|
+
emit(eventName, data) {
|
|
243
|
+
return this.eventManager.emit(eventName, data);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Add an event listener
|
|
247
|
+
* @param eventName The name of the event to listen for
|
|
248
|
+
* @param listener The callback function to execute when the event is emitted
|
|
249
|
+
* @returns {this} Returns this instance for method chaining
|
|
250
|
+
*/
|
|
251
|
+
on(eventName, listener) {
|
|
252
|
+
this.eventManager.on(eventName, listener);
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Add a one-time event listener
|
|
257
|
+
* @param eventName The name of the event to listen for
|
|
258
|
+
* @param listener The callback function to execute when the event is emitted
|
|
259
|
+
* @returns {this} Returns this instance for method chaining
|
|
260
|
+
*/
|
|
261
|
+
once(eventName, listener) {
|
|
262
|
+
this.eventManager.once(eventName, listener);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Remove an event listener
|
|
267
|
+
* @param eventName The name of the event to stop listening for
|
|
268
|
+
* @param listener The callback function to remove
|
|
269
|
+
* @returns {this} Returns this instance for method chaining
|
|
270
|
+
*/
|
|
271
|
+
off(eventName, listener) {
|
|
272
|
+
this.eventManager.off(eventName, listener);
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Remove all listeners for a specific event or all events
|
|
277
|
+
* @param eventName Optional. The name of the event to remove listeners for.
|
|
278
|
+
* If not provided, all listeners for all events are removed.
|
|
279
|
+
* @returns {this} Returns this instance for method chaining
|
|
280
|
+
*/
|
|
281
|
+
removeAllListeners(eventName) {
|
|
282
|
+
this.eventManager.removeAllListeners(eventName);
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Set the current authentication method
|
|
287
|
+
* This is used by plugins to indicate which authentication method was used
|
|
288
|
+
* @param method The authentication method used
|
|
289
|
+
*/
|
|
290
|
+
setAuthMethod(method) {
|
|
291
|
+
this.authManager.setAuthMethod(method);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Get the current authentication method
|
|
295
|
+
* @returns The current authentication method or undefined if not set
|
|
296
|
+
*/
|
|
297
|
+
getAuthMethod() {
|
|
298
|
+
return this.authManager.getAuthMethod();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Saves the current user credentials to storage
|
|
302
|
+
*/
|
|
303
|
+
async saveCredentials(credentials) {
|
|
304
|
+
try {
|
|
305
|
+
this.storage.setItem("userCredentials", JSON.stringify(credentials));
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
309
|
+
console.warn("Failed to save credentials to storage");
|
|
310
|
+
}
|
|
311
|
+
if (typeof console !== "undefined" && console.error) {
|
|
312
|
+
console.error(`Error saving credentials:`, error);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
getIsLoggedIn() {
|
|
317
|
+
return !!(this.user && this.user.is);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.ShogunCore = ShogunCore;
|
|
321
|
+
ShogunCore.API_VERSION = "^4.0.7";
|
|
322
|
+
// Global declarations are handled in the original core.ts file
|
|
323
|
+
// to avoid conflicts, we only set the window properties here
|
|
324
|
+
if (typeof window !== "undefined") {
|
|
325
|
+
window.Shogun = (config) => {
|
|
326
|
+
return new ShogunCore(config);
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
exports.default = ShogunCore;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decrypt = exports.encrypt = exports.deserializePrivateKey = exports.deserializePublicKey = exports.generateKeyPair = void 0;
|
|
4
|
+
const hashing_1 = require("./hashing");
|
|
5
|
+
// RSA Key Generation and Encryption/Decryption Methods
|
|
6
|
+
const generateKeyPair = async () => {
|
|
7
|
+
try {
|
|
8
|
+
const keyPair = await crypto.subtle.generateKey({
|
|
9
|
+
name: "RSA-OAEP",
|
|
10
|
+
modulusLength: 4096, // Can be 1024, 2048, or 4096
|
|
11
|
+
publicExponent: new Uint8Array([1, 0, 1]), // 65537 in bytes
|
|
12
|
+
hash: "SHA-256", // Can be "SHA-1", "SHA-256", "SHA-384", or "SHA-512"
|
|
13
|
+
}, true, // Whether the key is extractable
|
|
14
|
+
["encrypt", "decrypt"]);
|
|
15
|
+
// Export keys to JWK format for storage/transmission
|
|
16
|
+
const publicKeyJWK = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
|
|
17
|
+
const privateKeyJWK = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
|
|
18
|
+
return {
|
|
19
|
+
publicKey: publicKeyJWK,
|
|
20
|
+
privateKey: privateKeyJWK,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error("Error generating key pair:", error);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.generateKeyPair = generateKeyPair;
|
|
29
|
+
const deserializePublicKey = async (key) => {
|
|
30
|
+
try {
|
|
31
|
+
// If key is already a JWK object, use it directly
|
|
32
|
+
// If it's a string, parse it first
|
|
33
|
+
const jwkKey = typeof key === "string" ? JSON.parse(key) : key;
|
|
34
|
+
// Validate that required JWK properties exist
|
|
35
|
+
if (!jwkKey.kty) {
|
|
36
|
+
throw new Error('Invalid JWK: missing "kty" property');
|
|
37
|
+
}
|
|
38
|
+
const publicKey = await crypto.subtle.importKey("jwk", // Import format
|
|
39
|
+
jwkKey, // The key in JWK format
|
|
40
|
+
{
|
|
41
|
+
name: "RSA-OAEP", // Algorithm name
|
|
42
|
+
hash: "SHA-256", // Hash algorithm
|
|
43
|
+
}, true, // Extractable flag
|
|
44
|
+
["encrypt"]);
|
|
45
|
+
return publicKey;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("Error deserializing public key:", error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.deserializePublicKey = deserializePublicKey;
|
|
53
|
+
const deserializePrivateKey = async (key) => {
|
|
54
|
+
try {
|
|
55
|
+
// If key is already a JWK object, use it directly
|
|
56
|
+
// If it's a string, parse it first
|
|
57
|
+
const jwkKey = typeof key === "string" ? JSON.parse(key) : key;
|
|
58
|
+
// Validate that required JWK properties exist
|
|
59
|
+
if (!jwkKey.kty) {
|
|
60
|
+
throw new Error('Invalid JWK: missing "kty" property');
|
|
61
|
+
}
|
|
62
|
+
const privateKey = await crypto.subtle.importKey("jwk", // Import format
|
|
63
|
+
jwkKey, // The key in JWK format
|
|
64
|
+
{
|
|
65
|
+
name: "RSA-OAEP", // Algorithm name
|
|
66
|
+
hash: "SHA-256", // Hash algorithm
|
|
67
|
+
}, true, // Extractable flag
|
|
68
|
+
["decrypt"]);
|
|
69
|
+
return privateKey;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error("Error deserializing private key:", error);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.deserializePrivateKey = deserializePrivateKey;
|
|
77
|
+
const encrypt = async (message, publicKey) => {
|
|
78
|
+
const encodedMessage = new TextEncoder().encode(message);
|
|
79
|
+
const encrypted = await crypto.subtle.encrypt({
|
|
80
|
+
name: "RSA-OAEP",
|
|
81
|
+
}, publicKey, encodedMessage);
|
|
82
|
+
return (0, hashing_1.arrayBufferToBase64)(encrypted);
|
|
83
|
+
};
|
|
84
|
+
exports.encrypt = encrypt;
|
|
85
|
+
const decrypt = async (encryptedMessage, privateKey) => {
|
|
86
|
+
const buffer = (0, hashing_1.base64ToArrayBuffer)(encryptedMessage);
|
|
87
|
+
try {
|
|
88
|
+
const decrypted = await crypto.subtle.decrypt({
|
|
89
|
+
name: "RSA-OAEP",
|
|
90
|
+
}, privateKey, buffer);
|
|
91
|
+
const message = new TextDecoder().decode(decrypted);
|
|
92
|
+
return message;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error("Decryption error:", error);
|
|
96
|
+
throw new Error("Unable to decrypt message. Incorrect private key.");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
exports.decrypt = decrypt;
|