shogun-core 5.2.0 → 5.2.2
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/README.md +145 -1143
- 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 -57
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RxJS = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
/**
|
|
7
|
+
* RxJS Integration for GunDB
|
|
8
|
+
* Provides reactive programming capabilities for GunDB data
|
|
9
|
+
*/
|
|
10
|
+
class RxJS {
|
|
11
|
+
/**
|
|
12
|
+
* Initialize GunRxJS with a GunDB instance
|
|
13
|
+
* @param gun - GunDB instance
|
|
14
|
+
*/
|
|
15
|
+
constructor(gun) {
|
|
16
|
+
this.gun = gun;
|
|
17
|
+
this.user = gun.user();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the current user
|
|
21
|
+
* @returns The current user
|
|
22
|
+
*/
|
|
23
|
+
getUser() {
|
|
24
|
+
return this.user;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the current user's public key
|
|
28
|
+
* @returns The current user's public key
|
|
29
|
+
*/
|
|
30
|
+
getUserPub() {
|
|
31
|
+
return this.user.is?.pub;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Observe a Gun node for changes
|
|
35
|
+
* @param path - Path to observe (can be a string or a Gun chain)
|
|
36
|
+
* @returns Observable that emits whenever the node changes
|
|
37
|
+
*/
|
|
38
|
+
observe(path) {
|
|
39
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
40
|
+
let node;
|
|
41
|
+
if (Array.isArray(path)) {
|
|
42
|
+
// Support array paths by chaining get calls
|
|
43
|
+
node = this.gun.get(path[0]);
|
|
44
|
+
for (let i = 1; i < path.length; i++) {
|
|
45
|
+
node = node.get(path[i]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (typeof path === "string") {
|
|
49
|
+
node = this.gun.get(path);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
node = path;
|
|
53
|
+
}
|
|
54
|
+
// Subscribe to changes
|
|
55
|
+
const unsub = node.on((data, key) => {
|
|
56
|
+
if (data === null || data === undefined) {
|
|
57
|
+
subscriber.next(null);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Remove Gun metadata before emitting
|
|
61
|
+
if (typeof data === "object" && data !== null) {
|
|
62
|
+
const cleanData = this.removeGunMeta(data);
|
|
63
|
+
subscriber.next(cleanData);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
subscriber.next(data);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// Return teardown logic
|
|
70
|
+
return () => {
|
|
71
|
+
if (unsub && typeof unsub === "function") {
|
|
72
|
+
unsub();
|
|
73
|
+
}
|
|
74
|
+
node.off();
|
|
75
|
+
};
|
|
76
|
+
}).pipe((0, operators_1.distinctUntilChanged)((prev, curr) => {
|
|
77
|
+
return JSON.stringify(prev) === JSON.stringify(curr);
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Match data based on Gun's '.map()' and convert to Observable
|
|
82
|
+
* @param path - Path to the collection
|
|
83
|
+
* @param matchFn - Optional function to filter results
|
|
84
|
+
* @returns Observable array of matched items
|
|
85
|
+
*/
|
|
86
|
+
match(path, matchFn) {
|
|
87
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
88
|
+
if (!path) {
|
|
89
|
+
subscriber.next([]);
|
|
90
|
+
subscriber.complete();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const node = typeof path === "string" ? this.gun.get(path) : path;
|
|
94
|
+
const results = {};
|
|
95
|
+
const unsub = node.map().on((data, key) => {
|
|
96
|
+
// Skip soul key which is Gun's internal reference
|
|
97
|
+
if (key === "_" || !data)
|
|
98
|
+
return;
|
|
99
|
+
if (matchFn && !matchFn(data)) {
|
|
100
|
+
// If matchFn is provided and returns false, remove item
|
|
101
|
+
if (results[key]) {
|
|
102
|
+
delete results[key];
|
|
103
|
+
subscriber.next(Object.values(results));
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const cleanData = typeof data === "object" ? this.removeGunMeta(data) : data;
|
|
108
|
+
results[key] = cleanData;
|
|
109
|
+
subscriber.next(Object.values(results));
|
|
110
|
+
});
|
|
111
|
+
// Return teardown logic
|
|
112
|
+
return () => {
|
|
113
|
+
if (unsub && typeof unsub === "function") {
|
|
114
|
+
unsub();
|
|
115
|
+
}
|
|
116
|
+
node.off();
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Put data and return an Observable
|
|
122
|
+
* @param path - Path where to put the data
|
|
123
|
+
* @param data - Data to put
|
|
124
|
+
* @returns Observable that completes when the put is acknowledged
|
|
125
|
+
*/
|
|
126
|
+
put(path, data) {
|
|
127
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
128
|
+
const performPut = (target, value) => {
|
|
129
|
+
target.put(value, (ack) => {
|
|
130
|
+
if (ack.err) {
|
|
131
|
+
subscriber.error(new Error(ack.err));
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
subscriber.next(value);
|
|
135
|
+
subscriber.complete();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
if (typeof path === "string" || Array.isArray(path)) {
|
|
140
|
+
// Path-based put
|
|
141
|
+
let node;
|
|
142
|
+
if (Array.isArray(path)) {
|
|
143
|
+
node = this.gun.get(path[0]);
|
|
144
|
+
for (let i = 1; i < path.length; i++)
|
|
145
|
+
node = node.get(path[i]);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
node = this.gun.get(path);
|
|
149
|
+
}
|
|
150
|
+
performPut(node, data);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Root-level put
|
|
154
|
+
performPut(this.gun, path);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Backward-compatible overload that accepts optional callback like tests expect
|
|
160
|
+
*/
|
|
161
|
+
putCompat(data, callback) {
|
|
162
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
163
|
+
this.gun.put(data, (ack) => {
|
|
164
|
+
if (callback)
|
|
165
|
+
callback(ack);
|
|
166
|
+
if (ack.err) {
|
|
167
|
+
subscriber.error(new Error(ack.err));
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
subscriber.next(data);
|
|
171
|
+
subscriber.complete();
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Set data on a node and return an Observable
|
|
178
|
+
* @param path - Path to the collection
|
|
179
|
+
* @param data - Data to set
|
|
180
|
+
* @returns Observable that completes when the set is acknowledged
|
|
181
|
+
*/
|
|
182
|
+
set(path, data) {
|
|
183
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
184
|
+
const performSet = (target, value) => {
|
|
185
|
+
target.set(value, (ack) => {
|
|
186
|
+
if (ack.err) {
|
|
187
|
+
subscriber.error(new Error(ack.err));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
subscriber.next(value);
|
|
191
|
+
subscriber.complete();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
if (typeof path === "string" || Array.isArray(path)) {
|
|
196
|
+
let node;
|
|
197
|
+
if (Array.isArray(path)) {
|
|
198
|
+
node = this.gun.get(path[0]);
|
|
199
|
+
for (let i = 1; i < path.length; i++)
|
|
200
|
+
node = node.get(path[i]);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
node = this.gun.get(path);
|
|
204
|
+
}
|
|
205
|
+
performSet(node, data);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
performSet(this.gun, path);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
setCompat(data, callback) {
|
|
213
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
214
|
+
this.gun.set(data, (ack) => {
|
|
215
|
+
if (callback)
|
|
216
|
+
callback(ack);
|
|
217
|
+
if (ack.err) {
|
|
218
|
+
subscriber.error(new Error(ack.err));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
subscriber.next(data);
|
|
222
|
+
subscriber.complete();
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get data once and return as Observable
|
|
229
|
+
* @param path - Path to get data from
|
|
230
|
+
* @returns Observable that emits the data once
|
|
231
|
+
*/
|
|
232
|
+
once(path) {
|
|
233
|
+
let node;
|
|
234
|
+
if (typeof path === "string") {
|
|
235
|
+
node = this.gun.get(path);
|
|
236
|
+
}
|
|
237
|
+
else if (path) {
|
|
238
|
+
node = path;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
node = this.gun;
|
|
242
|
+
}
|
|
243
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
244
|
+
node.once((data) => {
|
|
245
|
+
if (data === undefined || data === null) {
|
|
246
|
+
subscriber.next(null);
|
|
247
|
+
subscriber.complete();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const cleanData = typeof data === "object" ? this.removeGunMeta(data) : data;
|
|
251
|
+
subscriber.next(cleanData);
|
|
252
|
+
subscriber.complete();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Compute derived values from gun data
|
|
258
|
+
* @param sources - Array of paths or observables to compute from
|
|
259
|
+
* @param computeFn - Function that computes a new value from the sources
|
|
260
|
+
* @returns Observable of computed values
|
|
261
|
+
*/
|
|
262
|
+
compute(sources, computeFn) {
|
|
263
|
+
// Convert all sources to observables
|
|
264
|
+
const observables = sources.map((source) => {
|
|
265
|
+
if (typeof source === "string") {
|
|
266
|
+
return this.observe(source);
|
|
267
|
+
}
|
|
268
|
+
return source;
|
|
269
|
+
});
|
|
270
|
+
// Combine the latest values from all sources
|
|
271
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
272
|
+
let values = new Array(sources.length).fill(undefined);
|
|
273
|
+
let completed = new Array(sources.length).fill(false);
|
|
274
|
+
const subscriptions = observables.map((obs, index) => {
|
|
275
|
+
return obs.subscribe({
|
|
276
|
+
next: (value) => {
|
|
277
|
+
values[index] = value;
|
|
278
|
+
// Only compute if we have all values
|
|
279
|
+
if (values.every((v) => v !== undefined)) {
|
|
280
|
+
try {
|
|
281
|
+
const result = computeFn(...values);
|
|
282
|
+
subscriber.next(result);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
subscriber.error(error);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
error: (err) => subscriber.error(err),
|
|
290
|
+
complete: () => {
|
|
291
|
+
completed[index] = true;
|
|
292
|
+
if (completed.every((c) => c)) {
|
|
293
|
+
subscriber.complete();
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
// Return teardown logic
|
|
299
|
+
return () => {
|
|
300
|
+
subscriptions.forEach((sub) => sub.unsubscribe());
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* User put data and return an Observable (for authenticated users)
|
|
306
|
+
* @param path - Path where to put the data
|
|
307
|
+
* @param data - Data to put
|
|
308
|
+
* @returns Observable that completes when the put is acknowledged
|
|
309
|
+
*/
|
|
310
|
+
userPut(dataOrPath, maybeData, callback) {
|
|
311
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
312
|
+
const user = this.gun.user();
|
|
313
|
+
if (typeof dataOrPath === "string") {
|
|
314
|
+
user.get(dataOrPath).put(maybeData, (ack) => {
|
|
315
|
+
if (callback)
|
|
316
|
+
callback(ack);
|
|
317
|
+
if (ack.err) {
|
|
318
|
+
subscriber.error(new Error(ack.err));
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
subscriber.next(maybeData);
|
|
322
|
+
subscriber.complete();
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
user.put(dataOrPath, (ack) => {
|
|
328
|
+
if (callback)
|
|
329
|
+
callback(ack);
|
|
330
|
+
if (ack.err) {
|
|
331
|
+
subscriber.error(new Error(ack.err));
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
subscriber.next(dataOrPath);
|
|
335
|
+
subscriber.complete();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* User set data and return an Observable (for authenticated users)
|
|
343
|
+
* @param dataOrPath - Data to set or path where to set the data
|
|
344
|
+
* @param maybeData - Data to set (if first parameter is path)
|
|
345
|
+
* @param callback - Optional callback function
|
|
346
|
+
* @returns Observable that completes when the set is acknowledged
|
|
347
|
+
*/
|
|
348
|
+
userSet(dataOrPath, maybeData, callback) {
|
|
349
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
350
|
+
const user = this.gun.user();
|
|
351
|
+
if (typeof dataOrPath === "string") {
|
|
352
|
+
user.get(dataOrPath).set(maybeData, (ack) => {
|
|
353
|
+
if (callback)
|
|
354
|
+
callback(ack);
|
|
355
|
+
if (ack.err) {
|
|
356
|
+
subscriber.error(new Error(ack.err));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
subscriber.next(maybeData);
|
|
360
|
+
subscriber.complete();
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
user.set(dataOrPath, (ack) => {
|
|
366
|
+
if (callback)
|
|
367
|
+
callback(ack);
|
|
368
|
+
if (ack.err) {
|
|
369
|
+
subscriber.error(new Error(ack.err));
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
subscriber.next(dataOrPath);
|
|
373
|
+
subscriber.complete();
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* User once data and return an Observable (for authenticated users)
|
|
381
|
+
* @param path - Optional path to get data from
|
|
382
|
+
* @param callback - Optional callback function
|
|
383
|
+
* @returns Observable that emits the data once
|
|
384
|
+
*/
|
|
385
|
+
userOnce(path, callback) {
|
|
386
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
387
|
+
const user = this.gun.user();
|
|
388
|
+
const target = path ? user.get(path) : user;
|
|
389
|
+
target.once((data, ack) => {
|
|
390
|
+
if (callback)
|
|
391
|
+
callback(ack);
|
|
392
|
+
if (ack && ack.err) {
|
|
393
|
+
subscriber.error(new Error(ack.err));
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
subscriber.next(data);
|
|
397
|
+
subscriber.complete();
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Get user data
|
|
404
|
+
* @param path - Path to get data from
|
|
405
|
+
* @returns Observable that emits the data once
|
|
406
|
+
*/
|
|
407
|
+
userGet(path) {
|
|
408
|
+
return this.observe(this.gun.user().get(path));
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Observe user data
|
|
412
|
+
* @param path - Path to observe in user space
|
|
413
|
+
* @returns Observable that emits whenever the user data changes
|
|
414
|
+
*/
|
|
415
|
+
observeUser(path) {
|
|
416
|
+
if (path) {
|
|
417
|
+
return this.observe(this.gun.user().get(path));
|
|
418
|
+
}
|
|
419
|
+
return this.observe(this.gun.user().get("~"));
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Remove Gun metadata from an object
|
|
423
|
+
* @param obj - Object to clean
|
|
424
|
+
* @returns Cleaned object without Gun metadata
|
|
425
|
+
*/
|
|
426
|
+
removeGunMeta(obj) {
|
|
427
|
+
if (!obj || typeof obj !== "object")
|
|
428
|
+
return obj;
|
|
429
|
+
// Create a clean copy
|
|
430
|
+
const cleanObj = Array.isArray(obj) ? [] : {};
|
|
431
|
+
// Copy properties, skipping Gun metadata
|
|
432
|
+
Object.keys(obj).forEach((key) => {
|
|
433
|
+
// Skip Gun metadata
|
|
434
|
+
if (key === "_" || key === "#")
|
|
435
|
+
return;
|
|
436
|
+
const val = obj[key];
|
|
437
|
+
if (val && typeof val === "object") {
|
|
438
|
+
cleanObj[key] = this.removeGunMeta(val);
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
cleanObj[key] = val;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
return cleanObj;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
exports.RxJS = RxJS;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.CryptoIdentityManager = exports.normalizeSeedPhrase = exports.formatSeedPhrase = exports.deriveCredentialsFromMnemonic = exports.seedToPassword = exports.mnemonicToSeed = exports.validateSeedPhrase = exports.generateSeedPhrase = exports.autoQuickStart = exports.AutoQuickStart = exports.createSimpleAPI = exports.quickStart = exports.QuickStart = exports.SimpleGunAPI = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.SEA = exports.ShogunCore = exports.Gun = void 0;
|
|
21
|
+
const core_1 = require("./core");
|
|
22
|
+
Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return core_1.ShogunCore; } });
|
|
23
|
+
const db_1 = require("./gundb/db");
|
|
24
|
+
Object.defineProperty(exports, "RxJS", { enumerable: true, get: function () { return db_1.RxJS; } });
|
|
25
|
+
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return db_1.crypto; } });
|
|
26
|
+
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return db_1.derive; } });
|
|
27
|
+
Object.defineProperty(exports, "GunErrors", { enumerable: true, get: function () { return db_1.GunErrors; } });
|
|
28
|
+
Object.defineProperty(exports, "DataBase", { enumerable: true, get: function () { return db_1.DataBase; } });
|
|
29
|
+
// Import Simple API and improved types
|
|
30
|
+
const gundb_1 = require("./gundb");
|
|
31
|
+
Object.defineProperty(exports, "SimpleGunAPI", { enumerable: true, get: function () { return gundb_1.SimpleGunAPI; } });
|
|
32
|
+
Object.defineProperty(exports, "QuickStart", { enumerable: true, get: function () { return gundb_1.QuickStart; } });
|
|
33
|
+
Object.defineProperty(exports, "quickStart", { enumerable: true, get: function () { return gundb_1.quickStart; } });
|
|
34
|
+
Object.defineProperty(exports, "createSimpleAPI", { enumerable: true, get: function () { return gundb_1.createSimpleAPI; } });
|
|
35
|
+
Object.defineProperty(exports, "AutoQuickStart", { enumerable: true, get: function () { return gundb_1.AutoQuickStart; } });
|
|
36
|
+
Object.defineProperty(exports, "autoQuickStart", { enumerable: true, get: function () { return gundb_1.autoQuickStart; } });
|
|
37
|
+
const db_2 = require("./gundb/db");
|
|
38
|
+
Object.defineProperty(exports, "SEA", { enumerable: true, get: function () { return db_2.SEA; } });
|
|
39
|
+
const db_3 = __importDefault(require("./gundb/db"));
|
|
40
|
+
exports.Gun = db_3.default;
|
|
41
|
+
__exportStar(require("./utils/errorHandler"), exports);
|
|
42
|
+
__exportStar(require("./plugins"), exports);
|
|
43
|
+
__exportStar(require("./interfaces/shogun"), exports);
|
|
44
|
+
__exportStar(require("./config/simplified-config"), exports);
|
|
45
|
+
// Export seed phrase utilities for WebAuthn multi-device support
|
|
46
|
+
var seedPhrase_1 = require("./utils/seedPhrase");
|
|
47
|
+
Object.defineProperty(exports, "generateSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.generateSeedPhrase; } });
|
|
48
|
+
Object.defineProperty(exports, "validateSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.validateSeedPhrase; } });
|
|
49
|
+
Object.defineProperty(exports, "mnemonicToSeed", { enumerable: true, get: function () { return seedPhrase_1.mnemonicToSeed; } });
|
|
50
|
+
Object.defineProperty(exports, "seedToPassword", { enumerable: true, get: function () { return seedPhrase_1.seedToPassword; } });
|
|
51
|
+
Object.defineProperty(exports, "deriveCredentialsFromMnemonic", { enumerable: true, get: function () { return seedPhrase_1.deriveCredentialsFromMnemonic; } });
|
|
52
|
+
Object.defineProperty(exports, "formatSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.formatSeedPhrase; } });
|
|
53
|
+
Object.defineProperty(exports, "normalizeSeedPhrase", { enumerable: true, get: function () { return seedPhrase_1.normalizeSeedPhrase; } });
|
|
54
|
+
// Export crypto module
|
|
55
|
+
__exportStar(require("./crypto"), exports);
|
|
56
|
+
// Export managers
|
|
57
|
+
var CryptoIdentityManager_1 = require("./managers/CryptoIdentityManager");
|
|
58
|
+
Object.defineProperty(exports, "CryptoIdentityManager", { enumerable: true, get: function () { return CryptoIdentityManager_1.CryptoIdentityManager; } });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShogunEventEmitter = void 0;
|
|
4
|
+
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
5
|
+
/**
|
|
6
|
+
* Extended EventEmitter class with typed events for Shogun
|
|
7
|
+
* @class ShogunEventEmitter
|
|
8
|
+
* @extends EventEmitter
|
|
9
|
+
*/
|
|
10
|
+
class ShogunEventEmitter extends eventEmitter_1.EventEmitter {
|
|
11
|
+
/**
|
|
12
|
+
* Emit a typed Shogun event
|
|
13
|
+
* @template K - Event key type
|
|
14
|
+
* @param {K} event - Event name
|
|
15
|
+
* @param {ShogunEventMap[K]} data - Event data
|
|
16
|
+
* @returns {boolean} - Returns true if the event had listeners, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
emit(event, data) {
|
|
19
|
+
return super.emit(event, data);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register a listener for a typed Shogun event
|
|
23
|
+
* @template K - Event key type
|
|
24
|
+
* @param {K} event - Event name
|
|
25
|
+
* @param {(data: ShogunEventMap[K]) => void} listener - Event listener function
|
|
26
|
+
*/
|
|
27
|
+
on(event, listener) {
|
|
28
|
+
super.on(event, listener);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Remove a listener for a typed Shogun event
|
|
32
|
+
* @template K - Event key type
|
|
33
|
+
* @param {K} event - Event name
|
|
34
|
+
* @param {(data: ShogunEventMap[K]) => void} listener - Event listener function to remove
|
|
35
|
+
*/
|
|
36
|
+
off(event, listener) {
|
|
37
|
+
super.off(event, listener);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ShogunEventEmitter = ShogunEventEmitter;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CorePlugins = exports.PluginCategory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Standard plugin categories in ShogunCore
|
|
6
|
+
*/
|
|
7
|
+
var PluginCategory;
|
|
8
|
+
(function (PluginCategory) {
|
|
9
|
+
/** Authentication plugins (WebAuthn, MetaMask, Bitcoin) */
|
|
10
|
+
PluginCategory["Authentication"] = "authentication";
|
|
11
|
+
/** Wallet management plugins */
|
|
12
|
+
PluginCategory["Wallet"] = "wallet";
|
|
13
|
+
/** Privacy and anonymity plugins */
|
|
14
|
+
PluginCategory["Privacy"] = "privacy";
|
|
15
|
+
/** Decentralized identity plugins */
|
|
16
|
+
PluginCategory["Identity"] = "identity";
|
|
17
|
+
/** Other utility plugins */
|
|
18
|
+
PluginCategory["Utility"] = "utility";
|
|
19
|
+
/** Messages plugins */
|
|
20
|
+
PluginCategory["Messages"] = "messages";
|
|
21
|
+
/** Messaging plugins */
|
|
22
|
+
PluginCategory["Other"] = "other";
|
|
23
|
+
})(PluginCategory || (exports.PluginCategory = PluginCategory = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Standard names for built-in plugins
|
|
26
|
+
*/
|
|
27
|
+
var CorePlugins;
|
|
28
|
+
(function (CorePlugins) {
|
|
29
|
+
/** WebAuthn plugin */
|
|
30
|
+
CorePlugins["WebAuthn"] = "webauthn";
|
|
31
|
+
/** Ethereum plugin */
|
|
32
|
+
CorePlugins["Web3"] = "web3";
|
|
33
|
+
/** Bitcoin wallet plugin */
|
|
34
|
+
CorePlugins["Nostr"] = "nostr";
|
|
35
|
+
/** Zero-Knowledge Proof plugin */
|
|
36
|
+
CorePlugins["ZkProof"] = "zkproof";
|
|
37
|
+
})(CorePlugins || (exports.CorePlugins = CorePlugins = {}));
|