shogun-core 6.3.0 → 6.3.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.
@@ -838,7 +838,7 @@ export var demonstrateDoubleRatchet = function () { return __awaiter(void 0, voi
838
838
  case 0:
839
839
  _c.trys.push([0, 14, , 15]);
840
840
  console.log("🚀 Starting Double Ratchet demonstration...");
841
- return [4 /*yield*/, import("./signal-protocol")];
841
+ return [4 /*yield*/, import("./signal-protocol.js")];
842
842
  case 1:
843
843
  _a = _c.sent(), initializeSignalUser = _a.initializeSignalUser, getSignalPublicKeyBundle = _a.getSignalPublicKeyBundle, performSignalX3DHKeyExchange = _a.performSignalX3DHKeyExchange;
844
844
  return [4 /*yield*/, initializeSignalUser("Alice")];
@@ -90,7 +90,7 @@ function testInteractiveDoubleRatchet() {
90
90
  case 0:
91
91
  _b.trys.push([0, 15, , 16]);
92
92
  console.log("🔄 Starting Interactive Double Ratchet test...");
93
- return [4 /*yield*/, import("../crypto/signal-protocol")];
93
+ return [4 /*yield*/, import("../crypto/signal-protocol.js")];
94
94
  case 1:
95
95
  _a = _b.sent(), initializeSignalUser = _a.initializeSignalUser, getSignalPublicKeyBundle = _a.getSignalPublicKeyBundle, performSignalX3DHKeyExchange = _a.performSignalX3DHKeyExchange;
96
96
  return [4 /*yield*/, initializeSignalUser("Alice")];
package/dist/src/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // Import polyfills FIRST before any other imports
2
+ // This ensures Buffer and other Node.js polyfills are available
3
+ import "./polyfills";
1
4
  import { ShogunCore } from "./core.js";
2
5
  import { RxJS, crypto, derive, GunErrors, DataBase } from "./gundb/db.js";
3
6
  // Gun and SEA imports removed - users should import them directly from 'gun' package
@@ -17,3 +20,5 @@ export * from "./crypto/index.js";
17
20
  export { CryptoIdentityManager } from "./managers/CryptoIdentityManager.js";
18
21
  // Export storage
19
22
  export { ShogunStorage } from "./storage/storage.js";
23
+ // Export polyfill utilities
24
+ export { setBufferPolyfill } from "./polyfills.js";
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Browser polyfills for shogun-core
3
+ *
4
+ * This module sets up Buffer and other Node.js polyfills for browser environments.
5
+ * It must be imported before any other shogun-core modules that use these APIs.
6
+ *
7
+ * IMPORTANT: This polyfill relies on the bundler to provide Buffer.
8
+ *
9
+ * For Vite projects, configure vite.config.ts:
10
+ * ```ts
11
+ * import { defineConfig } from "vite";
12
+ * import { Buffer } from "buffer";
13
+ *
14
+ * export default defineConfig({
15
+ * define: { global: "globalThis" },
16
+ * resolve: { alias: { buffer: "buffer" } },
17
+ * optimizeDeps: { include: ["buffer"] },
18
+ * });
19
+ * ```
20
+ *
21
+ * Then import the polyfill in your main entry file BEFORE importing shogun-core:
22
+ * ```ts
23
+ * import { Buffer } from "buffer";
24
+ * import { setBufferPolyfill } from "shogun-core";
25
+ * setBufferPolyfill(Buffer);
26
+ * ```
27
+ *
28
+ * For Webpack projects, the ProvidePlugin should handle this automatically.
29
+ */
30
+ // Ensure process is available for browser
31
+ if (typeof window !== "undefined") {
32
+ if (!window.process) {
33
+ window.process = { env: {} };
34
+ }
35
+ if (!window.global) {
36
+ window.global = window;
37
+ }
38
+ }
39
+ // Export a function to manually set Buffer
40
+ // This should be called by users before importing shogun-core if using Vite
41
+ // Webpack projects should use ProvidePlugin which makes Buffer available automatically
42
+ export var setBufferPolyfill = function (Buffer) {
43
+ if (typeof window !== "undefined") {
44
+ window.Buffer = Buffer;
45
+ window.global = window.global || window;
46
+ window.global.Buffer = Buffer;
47
+ }
48
+ if (typeof globalThis !== "undefined") {
49
+ globalThis.Buffer = Buffer;
50
+ }
51
+ };
52
+ // Try to set Buffer from window if it's already available (from bundler)
53
+ if (typeof window !== "undefined" &&
54
+ window.Buffer &&
55
+ typeof Buffer === "undefined") {
56
+ setBufferPolyfill(window.Buffer);
57
+ }