shogun-core 6.4.0 → 6.4.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 CHANGED
@@ -14,7 +14,6 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
14
14
  - 🌐 **Decentralized Storage**: Built on GunDB for peer-to-peer data synchronization
15
15
  - 🔌 **Plugin System**: Extensible architecture with built-in plugins
16
16
  - 💼 **Smart Wallet**: Account Abstraction with multi-sig, social recovery, and batch transactions
17
- - 🔑 **Automatic Crypto Identity Management**: RSA, AES, Signal Protocol, PGP, MLS, and SFrame keys
18
17
  - 📱 **Reactive Programming**: RxJS integration for real-time data streams
19
18
  - 🛡️ **Security**: End-to-end encryption and secure key management
20
19
  - 🎯 **TypeScript**: Full TypeScript support with comprehensive type definitions
@@ -54,11 +53,6 @@ const shogun = new ShogunCore({
54
53
  enabled: true,
55
54
  defaultGroupId: "my-app-users",
56
55
  },
57
-
58
- // Optional: Configure crypto identity auto-generation
59
- crypto: {
60
- autoGenerateOnAuth: true, // Generate crypto identities automatically after auth
61
- },
62
56
  });
63
57
 
64
58
  // Register Smart Wallet plugin separately if needed
@@ -257,153 +251,6 @@ if (result.success) {
257
251
  }
258
252
  ```
259
253
 
260
- ## Crypto Identity Management
261
-
262
- Shogun Core provides automatic crypto identity generation for every authenticated user. All crypto identities are created automatically during the signup process and stored securely in the decentralized database.
263
-
264
- ### Automatic Identity Generation
265
-
266
- When a user signs up, Shogun Core automatically generates comprehensive crypto identities:
267
-
268
- - **RSA-4096 Key Pairs**: For asymmetric encryption and digital signatures
269
- - **AES-256 Symmetric Keys**: For fast symmetric encryption operations
270
- - **Signal Protocol Identities**: For end-to-end encrypted messaging
271
- - **PGP Key Pairs**: For email encryption and digital signatures
272
- - **MLS Groups**: For group messaging and collaboration
273
- - **SFrame Keys**: For media encryption and streaming
274
-
275
- ### Generating Crypto Identities
276
-
277
- ```typescript
278
- import { CryptoIdentityManager } from "shogun-core";
279
- import type { ISEAPair } from "gun/types";
280
-
281
- // Create CryptoIdentityManager instance
282
- const cryptoManager = new CryptoIdentityManager();
283
-
284
- // Generate crypto identities for a user
285
- const seaPair: ISEAPair = /* your SEA pair */;
286
- const result = await cryptoManager.generateAllIdentities("username", seaPair);
287
-
288
- if (result.success && result.identities) {
289
- console.log("RSA Key Pair:", !!result.identities.rsa);
290
- console.log("AES Key:", !!result.identities.aes);
291
- console.log("Signal Identity:", !!result.identities.signal);
292
- console.log("PGP Keys:", !!result.identities.pgp);
293
- console.log("MLS Group:", !!result.identities.mls);
294
- console.log("SFrame Key:", !!result.identities.sframe);
295
-
296
- // Access specific identity data
297
- if (result.identities.rsa) {
298
- console.log("RSA Public Key:", result.identities.rsa.publicKey);
299
- console.log("RSA Private Key:", result.identities.rsa.privateKey);
300
- }
301
-
302
- if (result.identities.aes) {
303
- console.log("AES Key:", result.identities.aes);
304
- }
305
-
306
- if (result.identities.signal) {
307
- console.log("Signal Identity:", result.identities.signal);
308
- }
309
-
310
- if (result.identities.pgp) {
311
- console.log("PGP Public Key:", result.identities.pgp.publicKey);
312
- console.log("PGP Private Key:", result.identities.pgp.privateKey);
313
- }
314
-
315
- if (result.identities.mls) {
316
- console.log("MLS Group ID:", result.identities.mls.groupId);
317
- console.log("MLS Member ID:", result.identities.mls.memberId);
318
- }
319
-
320
- if (result.identities.sframe) {
321
- console.log("SFrame Key ID:", result.identities.sframe.keyId);
322
- }
323
-
324
- // Note: Save identities to GunDB from the frontend if needed
325
- } else {
326
- console.error("Failed to generate identities:", result.error);
327
- }
328
- ```
329
-
330
- ### Complete Example
331
-
332
- ```typescript
333
- import { ShogunCore, CryptoIdentityManager } from "shogun-core";
334
- import Gun from "gun";
335
-
336
- // Initialize Shogun Core
337
- const gun = Gun({
338
- peers: ['https://gun-manhattan.herokuapp.com/gun']
339
- });
340
-
341
- const shogun = new ShogunCore({
342
- gunInstance: gun
343
- });
344
-
345
- // Register user
346
- const signupResult = await shogun.signUp("alice", "password123");
347
-
348
- if (signupResult.success && signupResult.sea) {
349
- console.log("User registered:", signupResult.username);
350
-
351
- // Generate crypto identities
352
- const cryptoManager = new CryptoIdentityManager();
353
- const result = await cryptoManager.generateAllIdentities(
354
- signupResult.username,
355
- signupResult.sea
356
- );
357
-
358
- if (result.success && result.identities) {
359
- console.log("✅ All crypto identities generated successfully");
360
- console.log("Identities available:", Object.keys(result.identities));
361
-
362
- // Save identities to GunDB from the frontend if needed
363
- // The manager only generates identities, saving is handled by the frontend
364
- }
365
- }
366
- ```
367
-
368
- ### Identity Structure
369
-
370
- The `CryptoIdentities` interface contains:
371
-
372
- ```typescript
373
- interface CryptoIdentities {
374
- rsa?: JWKKeyPair; // RSA-4096 key pair
375
- aes?: JsonWebKey; // AES-256 symmetric key
376
- signal?: SignalUser; // Signal Protocol identity
377
- pgp?: PGPKeyPair; // PGP key pair
378
- mls?: { // MLS group membership
379
- groupId: string;
380
- memberId: string;
381
- };
382
- sframe?: { // SFrame media key
383
- keyId: number;
384
- };
385
- createdAt: number; // Creation timestamp
386
- version: string; // Identity version
387
- }
388
- ```
389
-
390
- ### Error Handling
391
-
392
- ```typescript
393
- const result = await cryptoManager.generateAllIdentities("username", seaPair);
394
-
395
- if (!result.success) {
396
- switch (result.error) {
397
- case "Failed to generate crypto identities":
398
- console.log("Identity generation failed");
399
- break;
400
- default:
401
- console.error("Unknown error:", result.error);
402
- }
403
- }
404
- ```
405
-
406
-
407
254
  ## Browser Usage (CDN)
408
255
 
409
256
  ```html
@@ -492,15 +339,6 @@ interface ShogunCoreConfig {
492
339
  minEntropy?: number;
493
340
  };
494
341
 
495
- // Crypto identity configuration
496
- crypto?: {
497
- /**
498
- * When true (default), generate and save crypto identities automatically after auth.
499
- * Set to false to skip automatic crypto identity generation.
500
- */
501
- autoGenerateOnAuth?: boolean;
502
- };
503
-
504
342
  postAuth?: {
505
343
  enabled?: boolean;
506
344
  };
@@ -58716,6 +58716,8 @@ __webpack_require__.d(gundb_crypto_namespaceObject, {
58716
58716
  unsafeHash: () => (unsafeHash)
58717
58717
  });
58718
58718
 
58719
+ // EXTERNAL MODULE: ./node_modules/buffer/index.js
58720
+ var buffer = __webpack_require__("./node_modules/buffer/index.js");
58719
58721
  ;// ./src/polyfills.ts
58720
58722
  /* provided dependency */ var Buffer = __webpack_require__(/*! buffer */ "./node_modules/buffer/index.js")["Buffer"];
58721
58723
  /**
@@ -58747,6 +58749,7 @@ __webpack_require__.d(gundb_crypto_namespaceObject, {
58747
58749
  *
58748
58750
  * For Webpack projects, the ProvidePlugin should handle this automatically.
58749
58751
  */
58752
+
58750
58753
  // Ensure process is available for browser
58751
58754
  if (true) {
58752
58755
  if (!window.process) {
@@ -58775,6 +58778,9 @@ if ( true &&
58775
58778
  typeof Buffer === "undefined") {
58776
58779
  setBufferPolyfill(window.Buffer);
58777
58780
  }
58781
+ else if (typeof globalThis !== "undefined" && typeof Buffer === "undefined") {
58782
+ setBufferPolyfill(buffer.Buffer);
58783
+ }
58778
58784
 
58779
58785
  ;// ./src/utils/errorHandler.ts
58780
58786
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -123248,7 +123254,6 @@ var CONFIG = {
123248
123254
  PASSWORD: {
123249
123255
  MIN_LENGTH: 8,
123250
123256
  },
123251
- TIMEOUT: 11000, // 30 seconds
123252
123257
  };
123253
123258
  var DataBase = /** @class */ (function () {
123254
123259
  function DataBase(gun, appScope, core, sea) {
@@ -123531,19 +123536,12 @@ var DataBase = /** @class */ (function () {
123531
123536
  _a.trys.push([1, 3, , 4]);
123532
123537
  return [4 /*yield*/, new Promise(function (resolve) {
123533
123538
  var callbackInvoked = false;
123534
- var timeoutId = setTimeout(function () {
123535
- if (!callbackInvoked) {
123536
- callbackInvoked = true;
123537
- resolve({ success: false, error: "Pair auth timeout" });
123538
- }
123539
- }, CONFIG.TIMEOUT);
123540
123539
  user.auth(pair, function (ack) {
123541
123540
  var _a, _b, _c;
123542
123541
  if (callbackInvoked) {
123543
123542
  return;
123544
123543
  }
123545
123544
  callbackInvoked = true;
123546
- clearTimeout(timeoutId);
123547
123545
  if (ack.err) {
123548
123546
  // Could not login with pair, try to create user with username/password
123549
123547
  resolve({ success: false, error: ack.err });
@@ -123580,14 +123578,6 @@ var DataBase = /** @class */ (function () {
123580
123578
  console.log("[DB] Falling back to classic username/password account creation");
123581
123579
  return [4 /*yield*/, new Promise(function (resolve) {
123582
123580
  var callbackInvoked = false;
123583
- var timeoutId = setTimeout(function () {
123584
- if (!callbackInvoked) {
123585
- callbackInvoked = true;
123586
- console.log("[DB] Signup timeout");
123587
- _this.resetAuthState();
123588
- resolve({ success: false, error: "Signup timeout" });
123589
- }
123590
- }, CONFIG.TIMEOUT);
123591
123581
  user.create(normalizedUsername, password, function (createAck) {
123592
123582
  if (callbackInvoked) {
123593
123583
  return;
@@ -123597,7 +123587,6 @@ var DataBase = /** @class */ (function () {
123597
123587
  if (createAck.err ||
123598
123588
  (createAck.ok !== undefined && createAck.ok !== 0)) {
123599
123589
  callbackInvoked = true;
123600
- clearTimeout(timeoutId);
123601
123590
  _this.resetAuthState();
123602
123591
  resolve({ success: false, error: createAck.err || "Signup failed" });
123603
123592
  return;
@@ -123607,7 +123596,6 @@ var DataBase = /** @class */ (function () {
123607
123596
  var userPub = createAck.pub;
123608
123597
  if (!userPub) {
123609
123598
  callbackInvoked = true;
123610
- clearTimeout(timeoutId);
123611
123599
  _this.resetAuthState();
123612
123600
  resolve({
123613
123601
  success: false,
@@ -123622,7 +123610,6 @@ var DataBase = /** @class */ (function () {
123622
123610
  return;
123623
123611
  }
123624
123612
  callbackInvoked = true;
123625
- clearTimeout(timeoutId);
123626
123613
  if (authAck.err) {
123627
123614
  _this.resetAuthState();
123628
123615
  resolve({
@@ -123693,14 +123680,9 @@ var DataBase = /** @class */ (function () {
123693
123680
  user = this.gun.user();
123694
123681
  console.log("[DB] Login with username:", normalizedUsername);
123695
123682
  return [2 /*return*/, new Promise(function (resolve) {
123696
- var timeoutId = setTimeout(function () {
123697
- _this.resetAuthState();
123698
- resolve({ success: false, error: "Login timeout" });
123699
- }, CONFIG.TIMEOUT);
123700
123683
  if (pair) {
123701
123684
  user.auth(pair, function (ack) {
123702
123685
  var _a, _b, _c;
123703
- clearTimeout(timeoutId);
123704
123686
  if (ack.err) {
123705
123687
  _this.resetAuthState();
123706
123688
  resolve({ success: false, error: ack.err });
@@ -123731,7 +123713,6 @@ var DataBase = /** @class */ (function () {
123731
123713
  else {
123732
123714
  user.auth(normalizedUsername, password, function (ack) {
123733
123715
  var _a, _b, _c;
123734
- clearTimeout(timeoutId);
123735
123716
  if (ack.err) {
123736
123717
  _this.resetAuthState();
123737
123718
  resolve({ success: false, error: ack.err });
@@ -123819,13 +123800,8 @@ var DataBase = /** @class */ (function () {
123819
123800
  user = this.gun.user();
123820
123801
  console.log("[DB] Login with pair for username:", normalizedUsername);
123821
123802
  return [2 /*return*/, new Promise(function (resolve) {
123822
- var timeoutId = setTimeout(function () {
123823
- _this.resetAuthState();
123824
- resolve({ success: false, error: "Login with pair timeout" });
123825
- }, CONFIG.TIMEOUT);
123826
123803
  user.auth(pair, function (ack) {
123827
123804
  var _a, _b, _c;
123828
- clearTimeout(timeoutId);
123829
123805
  if (ack.err) {
123830
123806
  _this.resetAuthState();
123831
123807
  resolve({ success: false, error: ack.err });