shogun-core 3.3.4 → 3.3.6

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.
Files changed (154) hide show
  1. package/dist/browser/shogun-core.js +79760 -190313
  2. package/dist/browser/shogun-core.js.map +1 -1
  3. package/dist/{src/gundb → gundb}/db.js +7 -49
  4. package/dist/{src/index.js → index.js} +0 -1
  5. package/dist/{src/managers → managers}/CoreInitializer.js +0 -6
  6. package/dist/{src/storage → storage}/storage.js +0 -16
  7. package/dist/types/{src/index.d.ts → index.d.ts} +0 -1
  8. package/package.json +10 -32
  9. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_axios_index_js.shogun-core.js +0 -7
  10. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js +0 -4908
  11. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js.map +0 -1
  12. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js +0 -2109
  13. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js.map +0 -1
  14. package/dist/ship/examples/ephemeral-cli.js +0 -234
  15. package/dist/ship/examples/identity-cli.js +0 -503
  16. package/dist/ship/examples/messenger-cli.js +0 -745
  17. package/dist/ship/examples/stealth-cli.js +0 -433
  18. package/dist/ship/examples/storage-cli.js +0 -615
  19. package/dist/ship/examples/vault-cli.js +0 -444
  20. package/dist/ship/examples/wallet-cli.js +0 -767
  21. package/dist/ship/implementation/SHIP_00.js +0 -478
  22. package/dist/ship/implementation/SHIP_01.js +0 -433
  23. package/dist/ship/implementation/SHIP_02.js +0 -1366
  24. package/dist/ship/implementation/SHIP_03.js +0 -855
  25. package/dist/ship/implementation/SHIP_04.js +0 -589
  26. package/dist/ship/implementation/SHIP_05.js +0 -1064
  27. package/dist/ship/implementation/SHIP_06.js +0 -350
  28. package/dist/ship/implementation/SHIP_07.js +0 -635
  29. package/dist/ship/index.js +0 -17
  30. package/dist/ship/interfaces/ISHIP_00.js +0 -135
  31. package/dist/ship/interfaces/ISHIP_01.js +0 -128
  32. package/dist/ship/interfaces/ISHIP_02.js +0 -57
  33. package/dist/ship/interfaces/ISHIP_03.js +0 -61
  34. package/dist/ship/interfaces/ISHIP_04.js +0 -62
  35. package/dist/ship/interfaces/ISHIP_05.js +0 -59
  36. package/dist/ship/interfaces/ISHIP_06.js +0 -144
  37. package/dist/ship/interfaces/ISHIP_07.js +0 -194
  38. package/dist/types/ship/examples/ephemeral-cli.d.ts +0 -13
  39. package/dist/types/ship/examples/identity-cli.d.ts +0 -40
  40. package/dist/types/ship/examples/messenger-cli.d.ts +0 -37
  41. package/dist/types/ship/examples/stealth-cli.d.ts +0 -31
  42. package/dist/types/ship/examples/storage-cli.d.ts +0 -48
  43. package/dist/types/ship/examples/vault-cli.d.ts +0 -13
  44. package/dist/types/ship/examples/wallet-cli.d.ts +0 -131
  45. package/dist/types/ship/implementation/SHIP_00.d.ts +0 -113
  46. package/dist/types/ship/implementation/SHIP_01.d.ts +0 -80
  47. package/dist/types/ship/implementation/SHIP_02.d.ts +0 -297
  48. package/dist/types/ship/implementation/SHIP_03.d.ts +0 -127
  49. package/dist/types/ship/implementation/SHIP_04.d.ts +0 -76
  50. package/dist/types/ship/implementation/SHIP_05.d.ts +0 -70
  51. package/dist/types/ship/implementation/SHIP_06.d.ts +0 -66
  52. package/dist/types/ship/implementation/SHIP_07.d.ts +0 -101
  53. package/dist/types/ship/index.d.ts +0 -14
  54. package/dist/types/ship/interfaces/ISHIP_00.d.ts +0 -410
  55. package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -343
  56. package/dist/types/ship/interfaces/ISHIP_02.d.ts +0 -470
  57. package/dist/types/ship/interfaces/ISHIP_03.d.ts +0 -295
  58. package/dist/types/ship/interfaces/ISHIP_04.d.ts +0 -245
  59. package/dist/types/ship/interfaces/ISHIP_05.d.ts +0 -234
  60. package/dist/types/ship/interfaces/ISHIP_06.d.ts +0 -370
  61. package/dist/types/ship/interfaces/ISHIP_07.d.ts +0 -522
  62. /package/dist/{src/config → config}/simplified-config.js +0 -0
  63. /package/dist/{src/core.js → core.js} +0 -0
  64. /package/dist/{src/examples → examples}/api-test.js +0 -0
  65. /package/dist/{src/examples → examples}/simple-api-test.js +0 -0
  66. /package/dist/{src/gundb → gundb}/api.js +0 -0
  67. /package/dist/{src/gundb → gundb}/crypto.js +0 -0
  68. /package/dist/{src/gundb → gundb}/derive.js +0 -0
  69. /package/dist/{src/gundb → gundb}/errors.js +0 -0
  70. /package/dist/{src/gundb → gundb}/index.js +0 -0
  71. /package/dist/{src/gundb → gundb}/rxjs.js +0 -0
  72. /package/dist/{src/gundb → gundb}/types.js +0 -0
  73. /package/dist/{src/interfaces → interfaces}/common.js +0 -0
  74. /package/dist/{src/interfaces → interfaces}/events.js +0 -0
  75. /package/dist/{src/interfaces → interfaces}/plugin.js +0 -0
  76. /package/dist/{src/interfaces → interfaces}/shogun.js +0 -0
  77. /package/dist/{src/managers → managers}/AuthManager.js +0 -0
  78. /package/dist/{src/managers → managers}/EventManager.js +0 -0
  79. /package/dist/{src/managers → managers}/PluginManager.js +0 -0
  80. /package/dist/{src/migration-test.js → migration-test.js} +0 -0
  81. /package/dist/{src/plugins → plugins}/base.js +0 -0
  82. /package/dist/{src/plugins → plugins}/index.js +0 -0
  83. /package/dist/{src/plugins → plugins}/nostr/index.js +0 -0
  84. /package/dist/{src/plugins → plugins}/nostr/nostrConnector.js +0 -0
  85. /package/dist/{src/plugins → plugins}/nostr/nostrConnectorPlugin.js +0 -0
  86. /package/dist/{src/plugins → plugins}/nostr/nostrSigner.js +0 -0
  87. /package/dist/{src/plugins → plugins}/nostr/types.js +0 -0
  88. /package/dist/{src/plugins → plugins}/oauth/index.js +0 -0
  89. /package/dist/{src/plugins → plugins}/oauth/oauthConnector.js +0 -0
  90. /package/dist/{src/plugins → plugins}/oauth/oauthPlugin.js +0 -0
  91. /package/dist/{src/plugins → plugins}/oauth/types.js +0 -0
  92. /package/dist/{src/plugins → plugins}/web3/index.js +0 -0
  93. /package/dist/{src/plugins → plugins}/web3/types.js +0 -0
  94. /package/dist/{src/plugins → plugins}/web3/web3Connector.js +0 -0
  95. /package/dist/{src/plugins → plugins}/web3/web3ConnectorPlugin.js +0 -0
  96. /package/dist/{src/plugins → plugins}/web3/web3Signer.js +0 -0
  97. /package/dist/{src/plugins → plugins}/webauthn/index.js +0 -0
  98. /package/dist/{src/plugins → plugins}/webauthn/types.js +0 -0
  99. /package/dist/{src/plugins → plugins}/webauthn/webauthn.js +0 -0
  100. /package/dist/{src/plugins → plugins}/webauthn/webauthnPlugin.js +0 -0
  101. /package/dist/{src/plugins → plugins}/webauthn/webauthnSigner.js +0 -0
  102. /package/dist/types/{src/config → config}/simplified-config.d.ts +0 -0
  103. /package/dist/types/{src/core.d.ts → core.d.ts} +0 -0
  104. /package/dist/{src/types → types}/events.js +0 -0
  105. /package/dist/types/{src/examples → examples}/api-test.d.ts +0 -0
  106. /package/dist/types/{src/examples → examples}/simple-api-test.d.ts +0 -0
  107. /package/dist/types/{src/gundb → gundb}/api.d.ts +0 -0
  108. /package/dist/types/{src/gundb → gundb}/crypto.d.ts +0 -0
  109. /package/dist/types/{src/gundb → gundb}/db.d.ts +0 -0
  110. /package/dist/types/{src/gundb → gundb}/derive.d.ts +0 -0
  111. /package/dist/types/{src/gundb → gundb}/errors.d.ts +0 -0
  112. /package/dist/types/{src/gundb → gundb}/index.d.ts +0 -0
  113. /package/dist/types/{src/gundb → gundb}/rxjs.d.ts +0 -0
  114. /package/dist/types/{src/gundb → gundb}/types.d.ts +0 -0
  115. /package/dist/types/{src/interfaces → interfaces}/common.d.ts +0 -0
  116. /package/dist/types/{src/interfaces → interfaces}/events.d.ts +0 -0
  117. /package/dist/types/{src/interfaces → interfaces}/plugin.d.ts +0 -0
  118. /package/dist/types/{src/interfaces → interfaces}/shogun.d.ts +0 -0
  119. /package/dist/types/{src/managers → managers}/AuthManager.d.ts +0 -0
  120. /package/dist/types/{src/managers → managers}/CoreInitializer.d.ts +0 -0
  121. /package/dist/types/{src/managers → managers}/EventManager.d.ts +0 -0
  122. /package/dist/types/{src/managers → managers}/PluginManager.d.ts +0 -0
  123. /package/dist/types/{src/migration-test.d.ts → migration-test.d.ts} +0 -0
  124. /package/dist/types/{src/plugins → plugins}/base.d.ts +0 -0
  125. /package/dist/types/{src/plugins → plugins}/index.d.ts +0 -0
  126. /package/dist/types/{src/plugins → plugins}/nostr/index.d.ts +0 -0
  127. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnector.d.ts +0 -0
  128. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  129. /package/dist/types/{src/plugins → plugins}/nostr/nostrSigner.d.ts +0 -0
  130. /package/dist/types/{src/plugins → plugins}/nostr/types.d.ts +0 -0
  131. /package/dist/types/{src/plugins → plugins}/oauth/index.d.ts +0 -0
  132. /package/dist/types/{src/plugins → plugins}/oauth/oauthConnector.d.ts +0 -0
  133. /package/dist/types/{src/plugins → plugins}/oauth/oauthPlugin.d.ts +0 -0
  134. /package/dist/types/{src/plugins → plugins}/oauth/types.d.ts +0 -0
  135. /package/dist/types/{src/plugins → plugins}/web3/index.d.ts +0 -0
  136. /package/dist/types/{src/plugins → plugins}/web3/types.d.ts +0 -0
  137. /package/dist/types/{src/plugins → plugins}/web3/web3Connector.d.ts +0 -0
  138. /package/dist/types/{src/plugins → plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  139. /package/dist/types/{src/plugins → plugins}/web3/web3Signer.d.ts +0 -0
  140. /package/dist/types/{src/plugins → plugins}/webauthn/index.d.ts +0 -0
  141. /package/dist/types/{src/plugins → plugins}/webauthn/types.d.ts +0 -0
  142. /package/dist/types/{src/plugins → plugins}/webauthn/webauthn.d.ts +0 -0
  143. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  144. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnSigner.d.ts +0 -0
  145. /package/dist/{src/types → types}/shogun.js +0 -0
  146. /package/dist/types/{src/storage → storage}/storage.d.ts +0 -0
  147. /package/dist/types/{src/types → types}/events.d.ts +0 -0
  148. /package/dist/types/{src/types → types}/shogun.d.ts +0 -0
  149. /package/dist/types/{src/utils → utils}/errorHandler.d.ts +0 -0
  150. /package/dist/types/{src/utils → utils}/eventEmitter.d.ts +0 -0
  151. /package/dist/types/{src/utils → utils}/validation.d.ts +0 -0
  152. /package/dist/{src/utils → utils}/errorHandler.js +0 -0
  153. /package/dist/{src/utils → utils}/eventEmitter.js +0 -0
  154. /package/dist/{src/utils → utils}/validation.js +0 -0
@@ -1,350 +0,0 @@
1
- "use strict";
2
- /**
3
- * SHIP-06: Ephemeral P2P Messaging Implementation
4
- *
5
- * Two modes:
6
- * 1. Standalone: new SHIP_06(gunPeers[], roomId) - NO authentication!
7
- * - Uses ShogunCore internally with silent: true, disableAutoRecall: true
8
- * - Zero logs, zero storage, pure relay communication
9
- * - Room hashed with Web Crypto API SHA-256 for deterministic IDs
10
- *
11
- * 2. With Identity: new SHIP_06(ISHIP_00, roomId) - Authenticated sessions
12
- * - Uses existing Gun instance from SHIP-00
13
- * - All ShogunCore features available
14
- *
15
- * Architecture:
16
- * - Gun Relay for P2P communication (no WebRTC complexity!)
17
- * - SEA for ephemeral key generation and ECDH encryption
18
- * - Pure relay mode: radisk: false, localStorage: false, multicast: false
19
- */
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.SHIP_06 = void 0;
22
- const core_1 = require("../../src/core"); // ← Import diretto, NON da index!
23
- // ============================================================================
24
- // IMPLEMENTATION - STANDALONE VERSION (No ShogunCore dependency!)
25
- // ============================================================================
26
- class SHIP_06 {
27
- // Constructor overload: with identity OR standalone
28
- constructor(identityOrPeers, roomId, config) {
29
- this.identity = null;
30
- // State
31
- this.connected = false;
32
- this.swarmId = "";
33
- this.myAddress = "";
34
- this.myPair = null;
35
- // Gun nodes
36
- this.gun = null;
37
- this.sea = null;
38
- this.roomNode = null;
39
- this.presenceNode = null;
40
- this.messagesNode = null;
41
- // Peers
42
- this.peers = new Map();
43
- // Event handlers
44
- this.messageHandlers = [];
45
- this.encryptedMessageHandlers = [];
46
- this.peerSeenHandlers = [];
47
- this.peerLeftHandlers = [];
48
- // Heartbeat & cleanup
49
- this.heartbeatInterval = null;
50
- this.processedMessages = new Set();
51
- this.roomId = roomId;
52
- this.config = {
53
- debug: config?.debug || false,
54
- timeout: 30000,
55
- };
56
- if (Array.isArray(identityOrPeers)) {
57
- // STANDALONE MODE - ShogunCore with silent mode
58
- const shogunCore = new core_1.ShogunCore({
59
- gunOptions: {
60
- peers: identityOrPeers,
61
- radisk: false,
62
- localStorage: false,
63
- multicast: false,
64
- axe: false,
65
- },
66
- silent: true,
67
- disableAutoRecall: true,
68
- });
69
- this.gun = shogunCore.db.gun;
70
- this.sea = shogunCore.db.sea;
71
- this.identity = null;
72
- }
73
- else {
74
- // WITH IDENTITY MODE - use existing Gun from SHIP-00
75
- if (!identityOrPeers.isLoggedIn()) {
76
- throw new Error("User must be authenticated via SHIP-00");
77
- }
78
- this.identity = identityOrPeers;
79
- const shogun = identityOrPeers.getShogun();
80
- this.gun = shogun.db.gun;
81
- }
82
- }
83
- getIdentity() {
84
- if (!this.identity) {
85
- throw new Error("No identity - SHIP-06 running in standalone mode");
86
- }
87
- return this.identity;
88
- }
89
- async connect() {
90
- if (this.connected)
91
- return;
92
- // Generate ephemeral pair
93
- this.myPair = await this.sea.pair();
94
- if (!this.myPair) {
95
- throw new Error("Failed to generate SEA pair");
96
- }
97
- this.myAddress = this.myPair.pub.substring(0, 16);
98
- // Hash room ID DETERMINISTICAMENTE - Simple SHA256 hash
99
- if (this.identity) {
100
- const shogun = this.identity.getShogun();
101
- this.swarmId = await shogun.db.crypto.hashText(this.roomId);
102
- }
103
- else {
104
- // Standalone: use simple deterministic hash
105
- // SEA.work with different calls produces different results, so we use a simple hash
106
- const encoder = new TextEncoder();
107
- const data = encoder.encode(this.roomId);
108
- // Use Web Crypto API for deterministic SHA-256 hash
109
- if (typeof crypto !== "undefined" && crypto.subtle) {
110
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
111
- const hashArray = Array.from(new Uint8Array(hashBuffer));
112
- this.swarmId = hashArray
113
- .map((b) => b.toString(16).padStart(2, "0"))
114
- .join("");
115
- }
116
- else {
117
- // Fallback: simple deterministic hash
118
- let hash = "";
119
- for (let i = 0; i < this.roomId.length; i++) {
120
- hash += this.roomId.charCodeAt(i).toString(16);
121
- }
122
- this.swarmId = hash;
123
- }
124
- }
125
- if (this.config.debug) {
126
- console.log(`🔑 Room ID: "${this.roomId}"`);
127
- console.log(`🔒 Swarm ID (hashed): ${this.swarmId.substring(0, 32)}...`);
128
- }
129
- // Setup Gun nodes
130
- this.roomNode = this.gun.get("ephemeral").get(this.swarmId);
131
- this.presenceNode = this.roomNode.get("presence");
132
- this.messagesNode = this.roomNode.get("messages");
133
- // Announce presence
134
- await this.announcePresence();
135
- // Start listening
136
- this.listenForPeers();
137
- this.listenForMessages();
138
- // Start heartbeat
139
- this.startHeartbeat();
140
- this.connected = true;
141
- }
142
- disconnect() {
143
- if (this.heartbeatInterval) {
144
- clearInterval(this.heartbeatInterval);
145
- }
146
- if (this.presenceNode && this.myAddress) {
147
- this.presenceNode.get(this.myAddress).put(null);
148
- }
149
- this.connected = false;
150
- }
151
- isConnected() {
152
- return this.connected;
153
- }
154
- getSwarmId() {
155
- return this.swarmId;
156
- }
157
- getAddress() {
158
- return this.myAddress;
159
- }
160
- // ========================================================================
161
- // PRESENCE
162
- // ========================================================================
163
- async announcePresence() {
164
- if (!this.myPair)
165
- return;
166
- const presenceData = {
167
- address: this.myAddress,
168
- pub: this.myPair.pub,
169
- epub: this.myPair.epub,
170
- timestamp: Date.now(),
171
- };
172
- if (this.config.debug) {
173
- console.log(`📡 Announcing presence: ${this.myAddress}`);
174
- }
175
- await this.presenceNode.get(this.myAddress).put(presenceData);
176
- }
177
- startHeartbeat() {
178
- this.heartbeatInterval = setInterval(() => {
179
- if (this.myPair) {
180
- this.presenceNode.get(this.myAddress).put({
181
- address: this.myAddress,
182
- pub: this.myPair.pub,
183
- epub: this.myPair.epub,
184
- timestamp: Date.now(),
185
- });
186
- }
187
- }, 3000);
188
- }
189
- listenForPeers() {
190
- if (this.config.debug) {
191
- console.log(`👂 Listening for peers on: ephemeral/${this.swarmId.substring(0, 20)}...`);
192
- }
193
- this.presenceNode.map().on((data, address) => {
194
- if (!data || !address || address === "_" || address === this.myAddress) {
195
- return;
196
- }
197
- if (!data.pub || !data.epub || !data.timestamp) {
198
- return;
199
- }
200
- const age = Date.now() - (data.timestamp || 0);
201
- const isOnline = age < 10000;
202
- if (!this.peers.has(address)) {
203
- this.peers.set(address, {
204
- address,
205
- pubKey: data.pub,
206
- epub: data.epub,
207
- pub: data.pub,
208
- connectedAt: data.timestamp,
209
- });
210
- if (isOnline) {
211
- this.peerSeenHandlers.forEach((h) => h(address));
212
- }
213
- }
214
- else {
215
- const peer = this.peers.get(address);
216
- if (peer && data.timestamp > peer.connectedAt) {
217
- peer.connectedAt = data.timestamp;
218
- peer.pubKey = data.pub;
219
- peer.epub = data.epub;
220
- peer.pub = data.pub;
221
- }
222
- }
223
- });
224
- }
225
- // ========================================================================
226
- // MESSAGING
227
- // ========================================================================
228
- async sendBroadcast(message) {
229
- if (!this.connected || !this.myPair) {
230
- throw new Error("Not connected");
231
- }
232
- if (this.peers.size === 0) {
233
- console.warn("⚠️ No peers connected");
234
- return;
235
- }
236
- for (const [address, peer] of this.peers.entries()) {
237
- try {
238
- const secret = await this.sea.secret(peer.epub, this.myPair);
239
- const encrypted = await this.sea.encrypt(message, secret);
240
- const msgId = `${Date.now()}-${this.myAddress}-${Math.random().toString(36).substring(2, 9)}`;
241
- await this.messagesNode.get(msgId).put({
242
- from: this.myAddress,
243
- fromPub: this.myPair.pub,
244
- fromEpub: this.myPair.epub,
245
- to: address,
246
- content: encrypted,
247
- timestamp: Date.now(),
248
- type: "broadcast",
249
- });
250
- }
251
- catch (error) {
252
- console.error(` ❌ Error sending to ${address.substring(0, 8)}:`, error);
253
- }
254
- }
255
- }
256
- async sendDirect(peerAddress, message) {
257
- const peer = this.peers.get(peerAddress);
258
- if (!peer)
259
- throw new Error(`Peer ${peerAddress} not found`);
260
- if (!this.myPair)
261
- throw new Error("No SEA pair");
262
- const secret = await this.sea.secret(peer.epub, this.myPair);
263
- const encrypted = await this.sea.encrypt(message, secret);
264
- const msgId = `${Date.now()}-${this.myAddress}-${Math.random().toString(36).substring(2, 9)}`;
265
- await this.messagesNode.get(msgId).put({
266
- from: this.myAddress,
267
- fromPub: this.myPair.pub,
268
- fromEpub: this.myPair.epub,
269
- to: peerAddress,
270
- content: encrypted,
271
- timestamp: Date.now(),
272
- type: "direct",
273
- });
274
- }
275
- listenForMessages() {
276
- this.messagesNode.map().on(async (data, msgId) => {
277
- if (!data || msgId === "_" || this.processedMessages.has(msgId))
278
- return;
279
- if (data.to !== this.myAddress || data.from === this.myAddress)
280
- return;
281
- this.processedMessages.add(msgId);
282
- console.log(`\n📬 MESSAGE RECEIVED!`);
283
- console.log(` From: ${data.from.substring(0, 12)}...`);
284
- try {
285
- let peer = this.peers.get(data.from);
286
- if (!peer && data.fromPub && data.fromEpub) {
287
- peer = {
288
- address: data.from,
289
- pubKey: data.fromPub,
290
- epub: data.fromEpub,
291
- pub: data.fromPub,
292
- connectedAt: data.timestamp,
293
- };
294
- this.peers.set(data.from, peer);
295
- }
296
- if (!peer || !this.myPair)
297
- return;
298
- const senderEpub = data.fromEpub || peer.epub;
299
- const secret = await this.sea.secret(senderEpub, this.myPair);
300
- const decrypted = await this.sea.decrypt(data.content, secret);
301
- if (!decrypted)
302
- return;
303
- console.log(` Content: "${decrypted}"`);
304
- const ephemeralMsg = {
305
- from: data.from,
306
- fromPubKey: data.fromPub || peer.pubKey || "",
307
- content: decrypted,
308
- timestamp: data.timestamp,
309
- type: data.type,
310
- };
311
- this.messageHandlers.forEach((h) => h(ephemeralMsg));
312
- }
313
- catch (error) {
314
- if (this.config.debug) {
315
- console.error(` ❌ Error:`, error);
316
- }
317
- }
318
- });
319
- }
320
- // ========================================================================
321
- // EVENT HANDLERS
322
- // ========================================================================
323
- onMessage(callback) {
324
- this.messageHandlers.push(callback);
325
- }
326
- onPeerSeen(callback) {
327
- this.peerSeenHandlers.push(callback);
328
- }
329
- onPeerLeft(callback) {
330
- this.peerLeftHandlers.push(callback);
331
- }
332
- onEncryptedMessage(callback) {
333
- this.encryptedMessageHandlers.push(callback);
334
- }
335
- getPeers() {
336
- return Array.from(this.peers.keys());
337
- }
338
- getPeerInfo(address) {
339
- return this.peers.get(address) || null;
340
- }
341
- async getEphemeralPair() {
342
- if (!this.myPair)
343
- throw new Error("No ephemeral pair");
344
- return this.myPair;
345
- }
346
- async setEphemeralPair(pair) {
347
- this.myPair = pair;
348
- }
349
- }
350
- exports.SHIP_06 = SHIP_06;