@kynesyslabs/demosdk 2.1.14 → 2.2.0

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 (40) hide show
  1. package/build/abstraction/Identities.js.map +1 -1
  2. package/build/encryption/PQC/enigma.d.ts +83 -0
  3. package/build/encryption/PQC/enigma.js +243 -0
  4. package/build/encryption/PQC/enigma.js.map +1 -0
  5. package/build/encryption/PQC/falconts/falcon.d.ts +130 -0
  6. package/build/encryption/PQC/falconts/falcon.js +228 -0
  7. package/build/encryption/PQC/falconts/falcon.js.map +1 -0
  8. package/build/encryption/PQC/falconts/index.d.ts +4 -0
  9. package/build/encryption/PQC/falconts/index.js +19 -0
  10. package/build/encryption/PQC/falconts/index.js.map +1 -0
  11. package/build/encryption/PQC/falconts/mnemonic.d.ts +27 -0
  12. package/build/encryption/PQC/falconts/mnemonic.js +109 -0
  13. package/build/encryption/PQC/falconts/mnemonic.js.map +1 -0
  14. package/build/encryption/PQC/falconts/wordlist.d.ts +5 -0
  15. package/build/encryption/PQC/falconts/wordlist.js +216 -0
  16. package/build/encryption/PQC/falconts/wordlist.js.map +1 -0
  17. package/build/encryption/PQC/utils.d.ts +8 -0
  18. package/build/encryption/PQC/utils.js +16 -0
  19. package/build/encryption/PQC/utils.js.map +1 -0
  20. package/build/encryption/index.d.ts +2 -1
  21. package/build/encryption/index.js +4 -2
  22. package/build/encryption/index.js.map +1 -1
  23. package/build/encryption/unifiedCrypto.d.ts +125 -0
  24. package/build/encryption/unifiedCrypto.js +408 -0
  25. package/build/encryption/unifiedCrypto.js.map +1 -0
  26. package/build/instant_messaging/index.d.ts +300 -0
  27. package/build/instant_messaging/index.js +630 -0
  28. package/build/instant_messaging/index.js.map +1 -0
  29. package/build/multichain/core/btc.d.ts +4 -2
  30. package/build/multichain/core/btc.js +27 -4
  31. package/build/multichain/core/btc.js.map +1 -1
  32. package/build/utils/uint8Serialize.d.ts +2 -0
  33. package/build/utils/uint8Serialize.js +22 -0
  34. package/build/utils/uint8Serialize.js.map +1 -0
  35. package/build/websdk/utils/sha256.js +5 -1
  36. package/build/websdk/utils/sha256.js.map +1 -1
  37. package/package.json +9 -2
  38. package/build/encryption/PQC/index.d.ts +0 -136
  39. package/build/encryption/PQC/index.js +0 -405
  40. package/build/encryption/PQC/index.js.map +0 -1
@@ -0,0 +1,630 @@
1
+ "use strict";
2
+ /**
3
+ * MessagingPeer class for peer-to-peer communication through a signaling server
4
+ *
5
+ * This class handles:
6
+ * - Connection to signaling server
7
+ * - Peer registration with public key
8
+ * - Peer discovery
9
+ * - Message exchange with other peers
10
+ * - Public key requests
11
+ * - Automatic reconnection with exponential backoff
12
+ *
13
+ * Message Handling:
14
+ * - Messages are automatically encrypted when sent and decrypted when received
15
+ * - To handle incoming messages with type "message", register a handler using onMessage:
16
+ * ```typescript
17
+ * peer.onMessage((message, fromId) => {
18
+ * // Handle the decrypted message here
19
+ * console.log(`Message from ${fromId}:`, message);
20
+ * });
21
+ * ```
22
+ * - You can register multiple handlers for different purposes (each handler will receive the decrypted message and sender's ID)
23
+ * - Handlers are executed in the order they are registered
24
+ * - If no handlers are registered, messages will be silently ignored
25
+ * - For request-response patterns (like getting a peer's public key), use the Promise-based methods
26
+ * that handle the response matching automatically
27
+ *
28
+ * Request-Response Pattern:
29
+ * - The class provides a robust request-response pattern through the sendToServerAndWait method
30
+ * - This method sends a message to the server and waits for a specific response type
31
+ * - It supports custom error handling, retry logic, and filtering by additional criteria
32
+ * - Example usage:
33
+ * ```typescript
34
+ * // Basic usage
35
+ * const response = await peer.sendToServerAndWait(
36
+ * {
37
+ * type: "custom_action",
38
+ * payload: { someData: "value" }
39
+ * },
40
+ * "custom_action_success"
41
+ * );
42
+ *
43
+ * // With retry logic
44
+ * const response = await peer.sendToServerAndWait(
45
+ * {
46
+ * type: "custom_action",
47
+ * payload: { someData: "value" }
48
+ * },
49
+ * "custom_action_success",
50
+ * {
51
+ * retryCount: 3,
52
+ * timeout: 5000
53
+ * }
54
+ * );
55
+ * ```
56
+ *
57
+ * Message Types:
58
+ * - "message": Encrypted peer-to-peer messages
59
+ * ```typescript
60
+ * // Example of a received message payload
61
+ * {
62
+ * type: "message",
63
+ * payload: {
64
+ * message: {
65
+ * algorithm: "ml-kem-aes",
66
+ * encryptedData: Uint8Array,
67
+ * cipherText: Uint8Array
68
+ * },
69
+ * fromId: "sender-peer-id"
70
+ * }
71
+ * }
72
+ *
73
+ * // After decryption, handlers receive:
74
+ * // message = "Hello, this is the decrypted message"
75
+ * // fromId = "sender-peer-id"
76
+ * ```
77
+ *
78
+ * Complete Example: Building a barebone messenger app and handling incoming messages
79
+ * ```typescript
80
+ * // In your application file (e.g., myMessenger.ts)
81
+ * import { MessagingPeer } from './path/to/instant_messaging';
82
+ *
83
+ * // Create a peer instance
84
+ * const peer = new MessagingPeer({
85
+ * serverUrl: 'ws://your-signaling-server:3000',
86
+ * clientId: 'your-unique-id',
87
+ * publicKey: yourPublicKey // Your ml-kem public key
88
+ * });
89
+ *
90
+ * // Connect to the server
91
+ * await peer.connect();
92
+ *
93
+ * // Register a handler for incoming messages
94
+ * peer.onMessage((message, fromId) => {
95
+ * // Print the message to the console
96
+ * console.log(`Message from ${fromId}:`, message);
97
+ *
98
+ * // If you're building a UI, you might update the DOM:
99
+ * const messageElement = document.createElement('div');
100
+ * messageElement.textContent = `${fromId}: ${message}`;
101
+ * document.getElementById('messages-container').appendChild(messageElement);
102
+ * });
103
+ *
104
+ * // Discover other peers
105
+ * const peers = await peer.discoverPeers();
106
+ * console.log('Available peers:', peers);
107
+ *
108
+ * // Send a message to a specific peer
109
+ * await peer.sendMessage('target-peer-id', 'Hello from me!');
110
+ * ```
111
+ *
112
+ * Usage:
113
+ * ```typescript
114
+ * const peer = new MessagingPeer({
115
+ * serverUrl: 'ws://localhost:3000',
116
+ * clientId: 'unique-id',
117
+ * publicKey: a ml-kem public key
118
+ * });
119
+ *
120
+ * // Connect and register
121
+ * await peer.connect();
122
+ *
123
+ * // Discover other peers
124
+ * const peers = await peer.discoverPeers();
125
+ *
126
+ * // Send a message
127
+ * await peer.sendMessage('target-peer-id', 'Hello!');
128
+ *
129
+ * // Listen for messages
130
+ * peer.onMessage((message, fromId) => {
131
+ * console.log(`Message from ${fromId}:`, message);
132
+ * });
133
+ * ```
134
+ */
135
+ Object.defineProperty(exports, "__esModule", { value: true });
136
+ exports.MessagingPeer = void 0;
137
+ const unifiedCrypto_1 = require("../encryption/unifiedCrypto");
138
+ const uint8Serialize_1 = require("../utils/uint8Serialize");
139
+ class MessagingPeer {
140
+ constructor(config) {
141
+ this.ws = null;
142
+ this.messageHandlers = new Set();
143
+ this.errorHandlers = new Set();
144
+ this.peerDisconnectedHandlers = new Set();
145
+ this.connectionStateHandlers = new Set();
146
+ this.connectedPeers = new Set();
147
+ this.messageQueue = [];
148
+ this.isConnected = false;
149
+ this.reconnectAttempts = 0;
150
+ this.maxReconnectAttempts = 10;
151
+ this.baseReconnectDelay = 1000; // 1 second
152
+ this.reconnectTimeout = null;
153
+ this.isReconnecting = false;
154
+ this.config = config;
155
+ }
156
+ /**
157
+ * Connects to the signaling server and registers the peer
158
+ * @returns Promise that resolves when connected and registered
159
+ */
160
+ async connect() {
161
+ console.log("[IM @ " + this.config.clientId + "] Connecting to the server", this.config.serverUrl);
162
+ return new Promise((resolve, reject) => {
163
+ try {
164
+ this.connectWebSocket();
165
+ this.reconnectAttempts = 0;
166
+ // Wait for the WebSocket to connect and register
167
+ const checkConnection = setInterval(() => {
168
+ if (this.isConnected) {
169
+ clearInterval(checkConnection);
170
+ // Now wait for registration confirmation
171
+ this.registerAndWait()
172
+ .then(() => {
173
+ console.log("[IM @ " +
174
+ this.config.clientId +
175
+ "] Connection and registration complete");
176
+ resolve();
177
+ })
178
+ .catch(error => {
179
+ console.error("[IM @ " +
180
+ this.config.clientId +
181
+ "] Registration failed", error);
182
+ reject(error);
183
+ });
184
+ }
185
+ }, 100);
186
+ // Set a timeout for the connection
187
+ setTimeout(() => {
188
+ clearInterval(checkConnection);
189
+ if (!this.isConnected) {
190
+ reject(new Error("Connection timeout"));
191
+ }
192
+ }, 10000);
193
+ }
194
+ catch (error) {
195
+ console.error("[IM @ " +
196
+ this.config.clientId +
197
+ "] Error connecting to the server", error);
198
+ reject(error);
199
+ }
200
+ });
201
+ }
202
+ /**
203
+ * Establishes WebSocket connection and sets up event handlers
204
+ */
205
+ connectWebSocket() {
206
+ if (this.ws) {
207
+ this.ws.close();
208
+ }
209
+ this.ws = new WebSocket(this.config.serverUrl);
210
+ this.isReconnecting = true;
211
+ this.notifyConnectionState("reconnecting");
212
+ this.ws.onopen = () => {
213
+ console.log("[IM @ " + this.config.clientId + "] Connected to the server");
214
+ this.isConnected = true;
215
+ this.isReconnecting = false;
216
+ this.reconnectAttempts = 0;
217
+ this.processMessageQueue();
218
+ this.notifyConnectionState("connected");
219
+ };
220
+ this.ws.onclose = () => {
221
+ console.log("[IM @ " +
222
+ this.config.clientId +
223
+ "] Disconnected from the server");
224
+ this.isConnected = false;
225
+ this.connectedPeers.clear();
226
+ this.notifyConnectionState("disconnected");
227
+ this.attemptReconnect();
228
+ };
229
+ this.ws.onerror = error => {
230
+ console.error("[IM @ " + this.config.clientId + "] Error on the websocket", error);
231
+ this.handleError({
232
+ type: "CONNECTION_ERROR",
233
+ details: error instanceof Error
234
+ ? error.message
235
+ : "WebSocket connection error",
236
+ });
237
+ };
238
+ this.ws.onmessage = event => {
239
+ this.handleMessage(JSON.parse(event.data));
240
+ };
241
+ }
242
+ /**
243
+ * Attempts to reconnect to the server with exponential backoff
244
+ */
245
+ attemptReconnect() {
246
+ if (this.reconnectAttempts >= this.maxReconnectAttempts ||
247
+ !this.isReconnecting) {
248
+ return;
249
+ }
250
+ const delay = Math.min(this.baseReconnectDelay * Math.pow(2, this.reconnectAttempts), 30000);
251
+ this.reconnectTimeout = setTimeout(() => {
252
+ this.reconnectAttempts++;
253
+ this.connectWebSocket();
254
+ }, delay);
255
+ }
256
+ /**
257
+ * Awaits a response for a specific message type
258
+ * @param messageType - The type of message to wait for
259
+ * @param filterFn - Optional function to filter messages by additional criteria
260
+ * @param timeout - Optional timeout in milliseconds (default: 10000)
261
+ * @returns Promise that resolves with the message payload or rejects with an error
262
+ */
263
+ async awaitResponse(messageType, filterFn, timeout = 10000) {
264
+ return new Promise((resolve, reject) => {
265
+ // Set a timeout to reject the promise if no response is received
266
+ const timeoutId = setTimeout(() => {
267
+ reject(new Error(`Timeout waiting for response of type: ${messageType}`));
268
+ }, timeout);
269
+ const handler = (message, fromId) => {
270
+ // Convert to Message object if needed
271
+ const msg = message && typeof message === "object" && "type" in message
272
+ ? message
273
+ : { type: "message", payload: message };
274
+ if (msg.type === messageType && (!filterFn || filterFn(msg))) {
275
+ clearTimeout(timeoutId);
276
+ resolve(msg.payload);
277
+ }
278
+ else if (msg.type === "error") {
279
+ console.error("[IM @ " +
280
+ this.config.clientId +
281
+ "] Received an error message: ", msg);
282
+ clearTimeout(timeoutId);
283
+ reject(new Error(msg.payload.details));
284
+ }
285
+ };
286
+ this.addTemporaryMessageHandler(handler);
287
+ });
288
+ }
289
+ /**
290
+ * Registers the peer with the signaling server
291
+ */
292
+ register() {
293
+ this.sendToServer({
294
+ type: "register",
295
+ payload: {
296
+ clientId: this.config.clientId,
297
+ publicKey: Array.from(this.config.publicKey),
298
+ },
299
+ });
300
+ console.log("[IM @ " + this.config.clientId + "] Register payload sent");
301
+ }
302
+ /**
303
+ * Registers the peer with the signaling server and waits for confirmation
304
+ * @returns Promise that resolves when registration is confirmed
305
+ */
306
+ async registerAndWait() {
307
+ // Creating a proof that shows our signing key
308
+ const proofSignature = await unifiedCrypto_1.unifiedCrypto.sign("ml-dsa", this.config.publicKey);
309
+ const serializedProofSignature = {
310
+ algorithm: "ml-dsa",
311
+ serializedSignedData: (0, uint8Serialize_1.serializeUint8Array)(proofSignature.signedData),
312
+ serializedPublicKey: (0, uint8Serialize_1.serializeUint8Array)(proofSignature.publicKey),
313
+ serializedMessage: (0, uint8Serialize_1.serializeUint8Array)(proofSignature.message),
314
+ };
315
+ // Sending the registration request and signing key proof
316
+ await this.sendToServerAndWait({
317
+ type: "register",
318
+ payload: {
319
+ clientId: this.config.clientId,
320
+ publicKey: Array.from(this.config.publicKey),
321
+ verification: serializedProofSignature,
322
+ },
323
+ }, "register");
324
+ console.log("[IM @ " + this.config.clientId + "] Registration confirmed");
325
+ }
326
+ /**
327
+ * Discovers all connected peers
328
+ * @returns Promise that resolves with an array of peer IDs
329
+ */
330
+ async discoverPeers() {
331
+ const response = await this.sendToServerAndWait({
332
+ type: "discover",
333
+ payload: {},
334
+ }, "discover");
335
+ this.connectedPeers = new Set(response.peers);
336
+ return response.peers;
337
+ }
338
+ /**
339
+ * Sends a message to a specific peer
340
+ * @param targetId - The ID of the target peer
341
+ * @param message - The message to send
342
+ */
343
+ async sendMessage(targetId, message) {
344
+ // Get the target peer's public key
345
+ // REVIEW Error handling if it fails?
346
+ const targetPublicKey = await this.requestPublicKey(targetId);
347
+ // Encrypt the message using ml-kem-aes
348
+ // NOTE This assumes that we have already exchanged public keys with the target peer
349
+ const bytesMessage = new TextEncoder().encode(message);
350
+ const encryptedMessage = await unifiedCrypto_1.unifiedCrypto.encrypt("ml-kem-aes", bytesMessage, targetPublicKey);
351
+ const serializedCipherText = (0, uint8Serialize_1.serializeUint8Array)(encryptedMessage.cipherText);
352
+ const serializedEncryptedData = (0, uint8Serialize_1.serializeUint8Array)(encryptedMessage.encryptedData);
353
+ const serializedEncryptedObject = {
354
+ algorithm: "ml-kem-aes",
355
+ serializedCipherText,
356
+ serializedEncryptedData,
357
+ };
358
+ // Send the encrypted message to the target peer
359
+ this.sendToServer({
360
+ type: "message",
361
+ payload: {
362
+ targetId: targetId,
363
+ message: serializedEncryptedObject,
364
+ },
365
+ });
366
+ }
367
+ /**
368
+ * Requests a peer's public key
369
+ * @param peerId - The ID of the peer whose public key to request
370
+ * @returns Promise that resolves with the peer's public key
371
+ */
372
+ async requestPublicKey(peerId) {
373
+ const response = await this.sendToServerAndWait({
374
+ type: "request_public_key",
375
+ payload: {
376
+ targetId: peerId,
377
+ },
378
+ }, "public_key_response", {
379
+ filterFn: message => message.payload.peerId === peerId,
380
+ });
381
+ return new Uint8Array(response.publicKey);
382
+ }
383
+ /**
384
+ * Adds a handler for incoming messages
385
+ * @param handler - Function to call when a message is received
386
+ */
387
+ onMessage(handler) {
388
+ this.messageHandlers.add(handler);
389
+ }
390
+ /**
391
+ * Adds a handler for errors
392
+ * @param handler - Function to call when an error occurs
393
+ */
394
+ onError(handler) {
395
+ this.errorHandlers.add(handler);
396
+ }
397
+ /**
398
+ * Adds a handler for peer disconnection events
399
+ * @param handler - Function to call when a peer disconnects
400
+ */
401
+ onPeerDisconnected(handler) {
402
+ this.peerDisconnectedHandlers.add(handler);
403
+ }
404
+ /**
405
+ * Adds a handler for connection state changes
406
+ * @param handler - Function to call when connection state changes
407
+ */
408
+ onConnectionStateChange(handler) {
409
+ this.connectionStateHandlers.add(handler);
410
+ }
411
+ /**
412
+ * Removes a message handler
413
+ * @param handler - The handler to remove
414
+ */
415
+ removeMessageHandler(handler) {
416
+ this.messageHandlers.delete(handler);
417
+ }
418
+ /**
419
+ * Removes an error handler
420
+ * @param handler - The handler to remove
421
+ */
422
+ removeErrorHandler(handler) {
423
+ this.errorHandlers.delete(handler);
424
+ }
425
+ /**
426
+ * Removes a peer disconnected handler
427
+ * @param handler - The handler to remove
428
+ */
429
+ removePeerDisconnectedHandler(handler) {
430
+ this.peerDisconnectedHandlers.delete(handler);
431
+ }
432
+ /**
433
+ * Removes a connection state change handler
434
+ * @param handler - The handler to remove
435
+ */
436
+ removeConnectionStateHandler(handler) {
437
+ this.connectionStateHandlers.delete(handler);
438
+ }
439
+ /**
440
+ * Closes the connection to the signaling server
441
+ */
442
+ disconnect() {
443
+ this.isReconnecting = false;
444
+ if (this.reconnectTimeout) {
445
+ clearTimeout(this.reconnectTimeout);
446
+ this.reconnectTimeout = null;
447
+ }
448
+ if (this.ws) {
449
+ this.ws.close();
450
+ this.ws = null;
451
+ this.isConnected = false;
452
+ this.connectedPeers.clear();
453
+ this.notifyConnectionState("disconnected");
454
+ }
455
+ }
456
+ /**
457
+ * Sends a message to the signaling server
458
+ * @param message - The message to send
459
+ */
460
+ sendToServer(message) {
461
+ if (!this.ws || !this.isConnected) {
462
+ this.messageQueue.push(message);
463
+ return;
464
+ }
465
+ try {
466
+ this.ws.send(JSON.stringify(message));
467
+ }
468
+ catch (error) {
469
+ this.handleError({
470
+ type: "SEND_ERROR",
471
+ details: error instanceof Error
472
+ ? error.message
473
+ : "Failed to send message",
474
+ });
475
+ }
476
+ }
477
+ /**
478
+ * Sends a message to the server and waits for a specific response type
479
+ * @param message - The message to send
480
+ * @param expectedResponseType - The type of response to wait for
481
+ * @param options - Additional options for handling the response
482
+ * @returns Promise that resolves with the response payload or rejects with an error
483
+ */
484
+ async sendToServerAndWait(message, expectedResponseType, options = {}) {
485
+ const { timeout = 10000, errorHandler, retryCount = 0, filterFn, } = options;
486
+ try {
487
+ // Send the message
488
+ this.sendToServer(message);
489
+ // Wait for the response
490
+ return await this.awaitResponse(expectedResponseType, filterFn, timeout);
491
+ }
492
+ catch (error) {
493
+ // Custom error handling
494
+ if (errorHandler) {
495
+ errorHandler(error);
496
+ }
497
+ // Retry logic if needed
498
+ if (retryCount > 0) {
499
+ console.log(`[IM] Retrying message (${retryCount} attempts remaining)...`);
500
+ return this.sendToServerAndWait(message, expectedResponseType, {
501
+ ...options,
502
+ retryCount: retryCount - 1,
503
+ });
504
+ }
505
+ throw error;
506
+ }
507
+ }
508
+ /**
509
+ * Handles incoming messages from the signaling server
510
+ * @param message - The received message
511
+ */
512
+ handleMessage(message) {
513
+ switch (message.type) {
514
+ case "message":
515
+ console.log("[IM @ " +
516
+ this.config.clientId +
517
+ "] Received an encrypted message");
518
+ //console.log(message)
519
+ // Decrypt the message using ml-kem-aes before passing to handlers
520
+ const serializedEncryptedMessage = message.payload // REVIEW Safeguard this?
521
+ .message; // REVIEW Safeguard this?
522
+ const cipherText = (0, uint8Serialize_1.deserializeUint8Array)(serializedEncryptedMessage.serializedCipherText);
523
+ const encryptedData = (0, uint8Serialize_1.deserializeUint8Array)(serializedEncryptedMessage.serializedEncryptedData);
524
+ const encryptedMessage = {
525
+ algorithm: serializedEncryptedMessage.algorithm,
526
+ cipherText,
527
+ encryptedData,
528
+ };
529
+ // NOTE When we receive a message, we need to decrypt it before passing it to the message handlers
530
+ // This is an async operation, so we need to handle it properly
531
+ console.log("[IM @ " + this.config.clientId + "] Decrypting message:");
532
+ const decryptedMessage = unifiedCrypto_1.unifiedCrypto
533
+ .decrypt(encryptedMessage)
534
+ .then(decryptedMessage => {
535
+ console.log("[IM @ " +
536
+ this.config.clientId +
537
+ "] Decrypted message: ", decryptedMessage);
538
+ // NOTE If something is added here, it will be executed for every message
539
+ // Below are the user-defined message handlers (through peer.onMessage)
540
+ this.messageHandlers.forEach(handler => {
541
+ handler(decryptedMessage, message.payload.fromId);
542
+ });
543
+ });
544
+ break;
545
+ case "register":
546
+ // Handle registration response
547
+ console.log("[IM @ " +
548
+ this.config.clientId +
549
+ "] Received registration response:", message.payload);
550
+ // Pass the message to any temporary handlers waiting for this response
551
+ this.messageHandlers.forEach(handler => {
552
+ handler(message, "");
553
+ });
554
+ break;
555
+ case "peer_disconnected":
556
+ this.connectedPeers.delete(message.payload.peerId);
557
+ this.peerDisconnectedHandlers.forEach(handler => {
558
+ handler(message.payload.peerId);
559
+ });
560
+ break;
561
+ /*case "error":
562
+ console.error("[IM @ " + this.config.clientId + "] Received an error message: ", message)
563
+ this.handleError({
564
+ type: message.payload.errorType,
565
+ details: message.payload.details,
566
+ })
567
+ break*/
568
+ default:
569
+ console.info("[IM @ " + this.config.clientId + "] Received a message: ");
570
+ console.log(message.type);
571
+ // Pass the message to any temporary handlers waiting for this response
572
+ this.messageHandlers.forEach(handler => {
573
+ handler(message, "");
574
+ });
575
+ break;
576
+ }
577
+ }
578
+ /**
579
+ * Handles errors
580
+ * @param error - The error to handle
581
+ */
582
+ handleError(error) {
583
+ this.errorHandlers.forEach(handler => {
584
+ handler(error);
585
+ });
586
+ }
587
+ /**
588
+ * Notifies connection state change handlers
589
+ * @param state - The new connection state
590
+ */
591
+ notifyConnectionState(state) {
592
+ this.connectionStateHandlers.forEach(handler => {
593
+ handler(state);
594
+ });
595
+ }
596
+ /**
597
+ * Adds a temporary message handler that will be removed after handling one message
598
+ * @param handler - The temporary handler to add
599
+ */
600
+ addTemporaryMessageHandler(handler) {
601
+ const tempHandler = (message, fromId) => {
602
+ // If the message is a Message object, pass it directly
603
+ if (message && typeof message === "object" && "type" in message) {
604
+ handler(message, fromId);
605
+ }
606
+ else {
607
+ // Otherwise, create a Message object from the data
608
+ handler({
609
+ type: "message",
610
+ payload: message,
611
+ }, fromId);
612
+ }
613
+ this.removeMessageHandler(tempHandler);
614
+ };
615
+ this.messageHandlers.add(tempHandler);
616
+ }
617
+ /**
618
+ * Process queued messages
619
+ */
620
+ processMessageQueue() {
621
+ while (this.messageQueue.length > 0) {
622
+ const message = this.messageQueue.shift();
623
+ if (message) {
624
+ this.sendToServer(message);
625
+ }
626
+ }
627
+ }
628
+ }
629
+ exports.MessagingPeer = MessagingPeer;
630
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/instant_messaging/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;;;AAEH,8DAA2E;AAC3E,2DAAmF;AA6BnF,MAAa,aAAa;IAgBtB,YAAY,MAA2B;QAfhC,OAAE,GAAqB,IAAI,CAAA;QAE1B,oBAAe,GAAwB,IAAI,GAAG,EAAE,CAAA;QAChD,kBAAa,GAAsB,IAAI,GAAG,EAAE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ACD,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;QAC1C,CAAC,CAAA;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IACzC,CAAC;IAED;;OAEG;IACK,mBAAmB;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;YACzC,IAAI,OAAO,EAAE,CAAC;gBACV,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;YAC9B,CAAC;QACL,CAAC;IACL,CAAC;CAEJ;AAloBD,sCAkoBC"}
@@ -37,6 +37,8 @@ export declare class BTC extends DefaultChain {
37
37
  signTransactions(psbts: bitcoin.Psbt[]): Promise<string[]>;
38
38
  getBalance(): Promise<string>;
39
39
  getEmptyTransaction(): Promise<any>;
40
- signMessage(): Promise<string>;
41
- verifyMessage(): Promise<boolean>;
40
+ signMessage(message: string, options?: {
41
+ privateKey?: string;
42
+ }): Promise<string>;
43
+ verifyMessage(message: string, signature: string, address: string): Promise<boolean>;
42
44
  }