@electrum-cash/network 4.0.0-development.6392223875 → 4.0.0-development.6401415161

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/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import {EventEmitter as $4QiMX$EventEmitter} from "events";
2
- import {Mutex as $4QiMX$Mutex} from "async-mutex";
3
- import $4QiMX$debug from "debug";
4
- import {parse as $4QiMX$parse, parseNumberAndBigInt as $4QiMX$parseNumberAndBigInt} from "lossless-json";
5
- import {connect as $4QiMX$connect, TLSSocket as $4QiMX$TLSSocket} from "tls";
6
- import {isIP as $4QiMX$isIP, connect as $4QiMX$connect1} from "net";
7
- import {WebSocket as $4QiMX$WebSocket} from "@monsterbitar/isomorphic-ws";
1
+ import {EventEmitter as $dvphU$EventEmitter} from "events";
2
+ import {Mutex as $dvphU$Mutex} from "async-mutex";
3
+ import $dvphU$debug from "debug";
4
+ import {parse as $dvphU$parse, parseNumberAndBigInt as $dvphU$parseNumberAndBigInt} from "lossless-json";
5
+ import {connect as $dvphU$connect, TLSSocket as $dvphU$TLSSocket} from "tls";
6
+ import {isIP as $dvphU$isIP, connect as $dvphU$connect1} from "net";
7
+ import {WebSocket as $dvphU$WebSocket} from "@monsterbitar/isomorphic-ws";
8
8
 
9
9
 
10
10
  function $parcel$export(e, n, v, s) {
@@ -12,21 +12,21 @@ function $parcel$export(e, n, v, s) {
12
12
  }
13
13
 
14
14
  // Create the debug logs.
15
- const $ef5ba40c8abe5a13$var$debug = {
16
- client: (0, $4QiMX$debug)("electrum-cash:client "),
17
- errors: (0, $4QiMX$debug)("electrum-cash:error "),
18
- warning: (0, $4QiMX$debug)("electrum-cash:warning"),
19
- network: (0, $4QiMX$debug)("electrum-cash:network"),
20
- ping: (0, $4QiMX$debug)("electrum-cash:pulses ")
15
+ const $623a31cc1663a627$var$debug = {
16
+ client: (0, $dvphU$debug)("electrum-cash:client "),
17
+ errors: (0, $dvphU$debug)("electrum-cash:error "),
18
+ warning: (0, $dvphU$debug)("electrum-cash:warning"),
19
+ network: (0, $dvphU$debug)("electrum-cash:network"),
20
+ ping: (0, $dvphU$debug)("electrum-cash:pulses ")
21
21
  };
22
22
  // Set log colors.
23
- $ef5ba40c8abe5a13$var$debug.client.color = "2";
24
- $ef5ba40c8abe5a13$var$debug.errors.color = "9";
25
- $ef5ba40c8abe5a13$var$debug.warning.color = "13";
26
- $ef5ba40c8abe5a13$var$debug.network.color = "4";
27
- $ef5ba40c8abe5a13$var$debug.ping.color = "8";
23
+ $623a31cc1663a627$var$debug.client.color = "2";
24
+ $623a31cc1663a627$var$debug.errors.color = "9";
25
+ $623a31cc1663a627$var$debug.warning.color = "13";
26
+ $623a31cc1663a627$var$debug.network.color = "4";
27
+ $623a31cc1663a627$var$debug.ping.color = "8";
28
28
  var // Export the logs.
29
- $ef5ba40c8abe5a13$export$2e2bcd8739ae039 = $ef5ba40c8abe5a13$var$debug;
29
+ $623a31cc1663a627$export$2e2bcd8739ae039 = $623a31cc1663a627$var$debug;
30
30
 
31
31
 
32
32
 
@@ -34,7 +34,7 @@ $ef5ba40c8abe5a13$export$2e2bcd8739ae039 = $ef5ba40c8abe5a13$var$debug;
34
34
  * Grouping of utilities that simplifies implementation of the Electrum protocol.
35
35
  *
36
36
  * @ignore
37
- */ class $c78f59d21170b7a6$var$ElectrumProtocol {
37
+ */ class $24139611f53a54b8$var$ElectrumProtocol {
38
38
  /**
39
39
  * Helper function that builds an Electrum request object.
40
40
  *
@@ -70,26 +70,26 @@ $ef5ba40c8abe5a13$export$2e2bcd8739ae039 = $ef5ba40c8abe5a13$var$debug;
70
70
  }
71
71
  }
72
72
  var // export the protocol.
73
- $c78f59d21170b7a6$export$2e2bcd8739ae039 = $c78f59d21170b7a6$var$ElectrumProtocol;
73
+ $24139611f53a54b8$export$2e2bcd8739ae039 = $24139611f53a54b8$var$ElectrumProtocol;
74
74
 
75
75
 
76
- var $a192ea5a4eec42d4$exports = {};
76
+ var $e83d2e7688025acd$exports = {};
77
77
 
78
- $parcel$export($a192ea5a4eec42d4$exports, "isVersionRejected", () => $a192ea5a4eec42d4$export$e1f38ab2b4ebdde6);
79
- $parcel$export($a192ea5a4eec42d4$exports, "isVersionNegotiated", () => $a192ea5a4eec42d4$export$9598f0c76aa41d73);
80
- const $a192ea5a4eec42d4$export$e1f38ab2b4ebdde6 = function(object) {
78
+ $parcel$export($e83d2e7688025acd$exports, "isVersionRejected", () => $e83d2e7688025acd$export$e1f38ab2b4ebdde6);
79
+ $parcel$export($e83d2e7688025acd$exports, "isVersionNegotiated", () => $e83d2e7688025acd$export$9598f0c76aa41d73);
80
+ const $e83d2e7688025acd$export$e1f38ab2b4ebdde6 = function(object) {
81
81
  return "error" in object;
82
82
  };
83
- const $a192ea5a4eec42d4$export$9598f0c76aa41d73 = function(object) {
83
+ const $e83d2e7688025acd$export$9598f0c76aa41d73 = function(object) {
84
84
  return "software" in object && "protocol" in object;
85
85
  };
86
86
 
87
87
 
88
- var $5abc8fb342687c03$exports = {};
88
+ var $d801b1f9b7fc3074$exports = {};
89
89
 
90
- $parcel$export($5abc8fb342687c03$exports, "ElectrumTransport", () => $5abc8fb342687c03$export$d048df559e6d3842);
91
- $parcel$export($5abc8fb342687c03$exports, "DefaultParameters", () => $5abc8fb342687c03$export$f019be48b3aacb1a);
92
- const $5abc8fb342687c03$export$d048df559e6d3842 = {
90
+ $parcel$export($d801b1f9b7fc3074$exports, "ElectrumTransport", () => $d801b1f9b7fc3074$export$d048df559e6d3842);
91
+ $parcel$export($d801b1f9b7fc3074$exports, "DefaultParameters", () => $d801b1f9b7fc3074$export$f019be48b3aacb1a);
92
+ const $d801b1f9b7fc3074$export$d048df559e6d3842 = {
93
93
  TCP: {
94
94
  Port: 50001,
95
95
  Scheme: "tcp"
@@ -107,11 +107,11 @@ const $5abc8fb342687c03$export$d048df559e6d3842 = {
107
107
  Scheme: "wss"
108
108
  }
109
109
  };
110
- const $5abc8fb342687c03$export$f019be48b3aacb1a = {
110
+ const $d801b1f9b7fc3074$export$f019be48b3aacb1a = {
111
111
  // Port number for TCP TLS connections
112
- PORT: $5abc8fb342687c03$export$d048df559e6d3842.TCP_TLS.Port,
112
+ PORT: $d801b1f9b7fc3074$export$d048df559e6d3842.TCP_TLS.Port,
113
113
  // Transport to connect to the Electrum server
114
- TRANSPORT_SCHEME: $5abc8fb342687c03$export$d048df559e6d3842.TCP_TLS.Scheme,
114
+ TRANSPORT_SCHEME: $d801b1f9b7fc3074$export$d048df559e6d3842.TCP_TLS.Scheme,
115
115
  // How long to wait before attempting to reconnect, in milliseconds.
116
116
  RECONNECT: 5000,
117
117
  // How long to wait for network operations before following up, in milliseconds.
@@ -131,7 +131,7 @@ const $5abc8fb342687c03$export$f019be48b3aacb1a = {
131
131
 
132
132
 
133
133
 
134
- class $ea64e414b68fe23b$export$22c0ca2c816c3e08 extends (0, $4QiMX$EventEmitter) {
134
+ class $0a4cf22b9d6c493c$export$22c0ca2c816c3e08 extends (0, $dvphU$EventEmitter) {
135
135
  /**
136
136
  * Connect to host:port using the specified transport
137
137
  *
@@ -150,39 +150,39 @@ class $ea64e414b68fe23b$export$22c0ca2c816c3e08 extends (0, $4QiMX$EventEmitter)
150
150
  this.once("connect", this.clearDisconnectTimerOnTimeout);
151
151
  // Define how to refer to the connection scheme in debug output.
152
152
  const socketTypes = {
153
- [(0, $5abc8fb342687c03$export$d048df559e6d3842).TCP.Scheme]: "a TCP Socket",
154
- [(0, $5abc8fb342687c03$export$d048df559e6d3842).TCP_TLS.Scheme]: "an encrypted TCP socket"
153
+ [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme]: "a TCP Socket",
154
+ [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme]: "an encrypted TCP socket"
155
155
  };
156
156
  // Log that we are trying to establish a connection.
157
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
158
- if (scheme !== (0, $5abc8fb342687c03$export$d048df559e6d3842).TCP.Scheme && scheme !== (0, $5abc8fb342687c03$export$d048df559e6d3842).TCP_TLS.Scheme) // Throw an error if an incorrect transport is specified
157
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
158
+ if (scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme && scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) // Throw an error if an incorrect transport is specified
159
159
  throw new Error("Incorrect transport specified");
160
- if (scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).TCP_TLS.Scheme) {
160
+ if (scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) {
161
161
  // Initialize connection options.
162
162
  const connectionOptions = {
163
163
  rejectUnauthorized: false
164
164
  };
165
165
  // If the hostname is not an IP address..
166
- if (!$4QiMX$isIP(host)) // Set the servername option which enables support for SNI.
166
+ if (!$dvphU$isIP(host)) // Set the servername option which enables support for SNI.
167
167
  // NOTE: SNI enables a server that hosts multiple domains to provide the appropriate TLS certificate.
168
168
  connectionOptions.serverName = host;
169
169
  // Initialize the socket (allowing self-signed certificates).
170
- this.tcpSocket = $4QiMX$connect(port, host, connectionOptions);
170
+ this.tcpSocket = $dvphU$connect(port, host, connectionOptions);
171
171
  // Add a 'secureConnect' listener that checks the authorization status of
172
172
  // the socket, and logs a warning when it uses a self signed certificate.
173
173
  this.tcpSocket.once("secureConnect", ()=>{
174
174
  // Cannot happen, since this event callback *only* exists on TLSSocket
175
- if (!(this.tcpSocket instanceof $4QiMX$TLSSocket)) return;
175
+ if (!(this.tcpSocket instanceof $dvphU$TLSSocket)) return;
176
176
  // Force cast authorizationError from Error to string (through unknown)
177
177
  // because it is incorrectly typed as an Error
178
178
  const authorizationError = this.tcpSocket.authorizationError;
179
- if (authorizationError === "DEPTH_ZERO_SELF_SIGNED_CERT") (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).warning(`Connection to ${host}:${port} uses a self-signed certificate`);
179
+ if (authorizationError === "DEPTH_ZERO_SELF_SIGNED_CERT") (0, $623a31cc1663a627$export$2e2bcd8739ae039).warning(`Connection to ${host}:${port} uses a self-signed certificate`);
180
180
  });
181
181
  // Trigger successful connection events.
182
182
  this.tcpSocket.on("secureConnect", this.onConnect.bind(this, socketTypes[scheme], host, port));
183
183
  } else {
184
184
  // Initialize the socket.
185
- this.tcpSocket = $4QiMX$connect1({
185
+ this.tcpSocket = $dvphU$connect1({
186
186
  host: host,
187
187
  port: port
188
188
  });
@@ -208,7 +208,7 @@ class $ea64e414b68fe23b$export$22c0ca2c816c3e08 extends (0, $4QiMX$EventEmitter)
208
208
  // If the onConnect function has already run, do not execute it again.
209
209
  if (this.onConnectHasRun) return;
210
210
  // Log that the connection has been established.
211
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
211
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
212
212
  // Forward the socket events
213
213
  this.tcpSocket.addListener("close", this.eventForwarders.disconnect);
214
214
  this.tcpSocket.addListener("data", this.eventForwarders.tcpData);
@@ -292,7 +292,7 @@ class $ea64e414b68fe23b$export$22c0ca2c816c3e08 extends (0, $4QiMX$EventEmitter)
292
292
  };
293
293
  }
294
294
  }
295
- class $ea64e414b68fe23b$export$25b4633f61498e1 extends (0, $4QiMX$EventEmitter) {
295
+ class $0a4cf22b9d6c493c$export$25b4633f61498e1 extends (0, $dvphU$EventEmitter) {
296
296
  /**
297
297
  * Connect to host:port using the specified transport
298
298
  *
@@ -311,18 +311,18 @@ class $ea64e414b68fe23b$export$25b4633f61498e1 extends (0, $4QiMX$EventEmitter)
311
311
  this.once("connect", this.clearDisconnectTimerOnTimeout);
312
312
  // Define how to refer to the connection scheme in debug output.
313
313
  const socketTypes = {
314
- [(0, $5abc8fb342687c03$export$d048df559e6d3842).WS.Scheme]: "a WebSocket",
315
- [(0, $5abc8fb342687c03$export$d048df559e6d3842).WSS.Scheme]: "an encrypted WebSocket"
314
+ [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme]: "a WebSocket",
315
+ [(0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme]: "an encrypted WebSocket"
316
316
  };
317
317
  // Log that we are trying to establish a connection.
318
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
319
- if (scheme !== (0, $5abc8fb342687c03$export$d048df559e6d3842).WS.Scheme && scheme !== (0, $5abc8fb342687c03$export$d048df559e6d3842).WSS.Scheme) // Throw an error if an incorrect transport is specified
318
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);
319
+ if (scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme && scheme !== (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Throw an error if an incorrect transport is specified
320
320
  throw new Error("Incorrect transport specified");
321
- if (scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).WSS.Scheme) // Initialize this.webSocket (rejecting self-signed certificates).
321
+ if (scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Initialize this.webSocket (rejecting self-signed certificates).
322
322
  // We reject self-signed certificates to match functionality of browsers.
323
- this.webSocket = new (0, $4QiMX$WebSocket)(`wss://${host}:${port}`);
323
+ this.webSocket = new (0, $dvphU$WebSocket)(`wss://${host}:${port}`);
324
324
  else // Initialize this.webSocket.
325
- this.webSocket = new (0, $4QiMX$WebSocket)(`ws://${host}:${port}`);
325
+ this.webSocket = new (0, $dvphU$WebSocket)(`ws://${host}:${port}`);
326
326
  // Trigger successful connection events.
327
327
  this.webSocket.addEventListener("open", this.onConnect.bind(this, socketTypes[scheme], host, port));
328
328
  // Forward the encountered errors.
@@ -338,7 +338,7 @@ class $ea64e414b68fe23b$export$25b4633f61498e1 extends (0, $4QiMX$EventEmitter)
338
338
  // If the onConnect function has already run, do not execute it again.
339
339
  if (this.onConnectHasRun) return;
340
340
  // Log that the connection has been established.
341
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
341
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Established ${connectionType} connection with '${host}:${port}'.`);
342
342
  // Forward the socket events
343
343
  this.webSocket.addEventListener("close", this.eventForwarders.disconnect);
344
344
  this.webSocket.addEventListener("message", this.eventForwarders.wsData);
@@ -431,37 +431,35 @@ class $ea64e414b68fe23b$export$25b4633f61498e1 extends (0, $4QiMX$EventEmitter)
431
431
  }
432
432
 
433
433
 
434
- var $a58372b18a18806e$exports = {};
434
+ var $db7c797e63383364$exports = {};
435
435
 
436
- $parcel$export($a58372b18a18806e$exports, "ClientState", () => $a58372b18a18806e$export$c4f81c6d30ca200f);
437
- $parcel$export($a58372b18a18806e$exports, "ConnectionStatus", () => $a58372b18a18806e$export$7516420eb880ab68);
436
+ $parcel$export($db7c797e63383364$exports, "ClientState", () => $db7c797e63383364$export$c4f81c6d30ca200f);
437
+ $parcel$export($db7c797e63383364$exports, "ConnectionStatus", () => $db7c797e63383364$export$7516420eb880ab68);
438
438
  // Disable indent rule for this file because it is broken (https://github.com/typescript-eslint/typescript-eslint/issues/1824)
439
439
  /* eslint-disable @typescript-eslint/indent */ /**
440
440
  * Enum that denotes the availability of an ElectrumClient.
441
441
  * @enum {number}
442
442
  * @property {0} UNAVAILABLE The client is currently not available.
443
443
  * @property {1} AVAILABLE The client is available for use.
444
- */ var $a58372b18a18806e$export$c4f81c6d30ca200f;
444
+ */ var $db7c797e63383364$export$c4f81c6d30ca200f;
445
445
  (function(ClientState) {
446
446
  ClientState[ClientState["UNAVAILABLE"] = 0] = "UNAVAILABLE";
447
447
  ClientState[ClientState["AVAILABLE"] = 1] = "AVAILABLE";
448
- })($a58372b18a18806e$export$c4f81c6d30ca200f || ($a58372b18a18806e$export$c4f81c6d30ca200f = {}));
449
- var $a58372b18a18806e$export$7516420eb880ab68;
448
+ })($db7c797e63383364$export$c4f81c6d30ca200f || ($db7c797e63383364$export$c4f81c6d30ca200f = {}));
449
+ var $db7c797e63383364$export$7516420eb880ab68;
450
450
  (function(ConnectionStatus) {
451
451
  ConnectionStatus[ConnectionStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
452
452
  ConnectionStatus[ConnectionStatus["CONNECTED"] = 1] = "CONNECTED";
453
453
  ConnectionStatus[ConnectionStatus["DISCONNECTING"] = 2] = "DISCONNECTING";
454
454
  ConnectionStatus[ConnectionStatus["CONNECTING"] = 3] = "CONNECTING";
455
455
  ConnectionStatus[ConnectionStatus["RECONNECTING"] = 4] = "RECONNECTING";
456
- })($a58372b18a18806e$export$7516420eb880ab68 || ($a58372b18a18806e$export$7516420eb880ab68 = {}));
456
+ })($db7c797e63383364$export$7516420eb880ab68 || ($db7c797e63383364$export$7516420eb880ab68 = {}));
457
457
 
458
458
 
459
459
 
460
460
  /**
461
461
  * Wrapper around TLS/WSS sockets that gracefully separates a network stream into Electrum protocol messages.
462
- *
463
- * @ignore
464
- */ class $1326c18f93f95fee$var$ElectrumConnection extends (0, $4QiMX$EventEmitter) {
462
+ */ class $ff134c9a9e1f7361$var$ElectrumConnection extends (0, $dvphU$EventEmitter) {
465
463
  /**
466
464
  * Sets up network configuration for an Electrum client connection.
467
465
  *
@@ -476,7 +474,7 @@ var $a58372b18a18806e$export$7516420eb880ab68;
476
474
  * @param {boolean} useBigInt whether to use bigint for numbers in json response.
477
475
  *
478
476
  * @throws {Error} if `version` is not a valid version string.
479
- */ constructor(application, version, host, port = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).PORT, scheme = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).USE_BIG_INT){
477
+ */ constructor(application, version, host, port = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PORT, scheme = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).USE_BIG_INT){
480
478
  // Initialize the event emitter.
481
479
  super();
482
480
  this.application = application;
@@ -488,12 +486,12 @@ var $a58372b18a18806e$export$7516420eb880ab68;
488
486
  this.pingInterval = pingInterval;
489
487
  this.reconnectInterval = reconnectInterval;
490
488
  this.useBigInt = useBigInt;
491
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED;
489
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
492
490
  this.timers = {};
493
491
  this.verifications = [];
494
492
  this.messageBuffer = "";
495
493
  // Check if the provided version is a valid version number.
496
- if (!(0, $c78f59d21170b7a6$export$2e2bcd8739ae039).versionRegexp.test(version)) // Throw an error since the version number was not valid.
494
+ if (!(0, $24139611f53a54b8$export$2e2bcd8739ae039).versionRegexp.test(version)) // Throw an error since the version number was not valid.
497
495
  throw new Error(`Provided version string (${version}) is not a valid protocol version number.`);
498
496
  // Create an initial network socket.
499
497
  this.createSocket();
@@ -508,10 +506,10 @@ var $a58372b18a18806e$export$7516420eb880ab68;
508
506
  /**
509
507
  * Create and configures a fresh socket and attaches all relevant listeners.
510
508
  */ createSocket() {
511
- if (this.scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).TCP.Scheme || this.scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).TCP_TLS.Scheme) // Initialize a new ElectrumTcpSocket
512
- this.socket = new (0, $ea64e414b68fe23b$export$22c0ca2c816c3e08)();
513
- else if (this.scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).WS.Scheme || this.scheme === (0, $5abc8fb342687c03$export$d048df559e6d3842).WSS.Scheme) // Initialize a new ElectrumWebSocket
514
- this.socket = new (0, $ea64e414b68fe23b$export$25b4633f61498e1)();
509
+ if (this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP.Scheme || this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).TCP_TLS.Scheme) // Initialize a new ElectrumTcpSocket
510
+ this.socket = new (0, $0a4cf22b9d6c493c$export$22c0ca2c816c3e08)();
511
+ else if (this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WS.Scheme || this.scheme === (0, $d801b1f9b7fc3074$export$d048df559e6d3842).WSS.Scheme) // Initialize a new ElectrumWebSocket
512
+ this.socket = new (0, $0a4cf22b9d6c493c$export$25b4633f61498e1)();
515
513
  else // Throw an error if an incorrect transport is specified
516
514
  throw new Error(`Provided transport (${this.scheme}) is not a valid ElectrumTransport`);
517
515
  // Set up handlers for connection and disconnection.
@@ -535,21 +533,23 @@ var $a58372b18a18806e$export$7516420eb880ab68;
535
533
  */ parseMessageChunk(data) {
536
534
  // Update the timestamp for when we last received data.
537
535
  this.lastReceivedTimestamp = Date.now();
536
+ // Emit a notification indicating that the connection has received data.
537
+ this.emit("received");
538
538
  // Clear and remove all verification timers.
539
539
  this.verifications.forEach((timer)=>clearTimeout(timer));
540
540
  this.verifications.length = 0;
541
541
  // Add the message to the current message buffer.
542
542
  this.messageBuffer += data;
543
543
  // Check if the new message buffer contains the statement delimiter.
544
- while(this.messageBuffer.includes((0, $c78f59d21170b7a6$export$2e2bcd8739ae039).statementDelimiter)){
544
+ while(this.messageBuffer.includes((0, $24139611f53a54b8$export$2e2bcd8739ae039).statementDelimiter)){
545
545
  // Split message buffer into statements.
546
- const statementParts = this.messageBuffer.split((0, $c78f59d21170b7a6$export$2e2bcd8739ae039).statementDelimiter);
546
+ const statementParts = this.messageBuffer.split((0, $24139611f53a54b8$export$2e2bcd8739ae039).statementDelimiter);
547
547
  // For as long as we still have statements to parse..
548
548
  while(statementParts.length > 1){
549
549
  // Move the first statement to its own variable.
550
550
  const currentStatementList = String(statementParts.shift());
551
551
  // Parse the statement into an object or list of objects.
552
- let statementList = (0, $4QiMX$parse)(currentStatementList, null, this.useBigInt ? (0, $4QiMX$parseNumberAndBigInt) : parseFloat);
552
+ let statementList = (0, $dvphU$parse)(currentStatementList, null, this.useBigInt ? (0, $dvphU$parseNumberAndBigInt) : parseFloat);
553
553
  // Wrap the statement in an array if it is not already a batched statement list.
554
554
  if (!Array.isArray(statementList)) statementList = [
555
555
  statementList
@@ -567,8 +567,6 @@ var $a58372b18a18806e$export$7516420eb880ab68;
567
567
  else {
568
568
  // Extract the software and protocol version reported.
569
569
  const [software, protocol] = currentStatement.result;
570
- // Store the reported software description.
571
- this.software = software;
572
570
  // Emit a successful version negotiation response signal.
573
571
  this.emit("version", {
574
572
  software: software,
@@ -594,9 +592,9 @@ var $a58372b18a18806e$export$7516420eb880ab68;
594
592
  * part of the message is queued in the user memory
595
593
  */ ping() {
596
594
  // Write a log message.
597
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);
595
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);
598
596
  // Craft a keep-alive message.
599
- const message = (0, $c78f59d21170b7a6$export$2e2bcd8739ae039).buildRequestObject("server.ping", [], "keepAlive");
597
+ const message = (0, $24139611f53a54b8$export$2e2bcd8739ae039).buildRequestObject("server.ping", [], "keepAlive");
600
598
  // Send the keep-alive message.
601
599
  const status = this.send(message);
602
600
  // Return the ping status.
@@ -609,14 +607,14 @@ var $a58372b18a18806e$export$7516420eb880ab68;
609
607
  * @returns a promise resolving when the connection is established
610
608
  */ async connect() {
611
609
  // If we are already connected return true.
612
- if (this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED) return;
610
+ if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) return;
613
611
  // Indicate that the connection is connecting
614
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTING;
612
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTING;
615
613
  // Define a function to wrap connection as a promise.
616
614
  const connectionResolver = (resolve, reject)=>{
617
615
  const rejector = (error)=>{
618
616
  // Set the status back to disconnected
619
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED;
617
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
620
618
  // Reject with the error as reason
621
619
  reject(error);
622
620
  };
@@ -626,24 +624,24 @@ var $a58372b18a18806e$export$7516420eb880ab68;
626
624
  // Define a function to wrap version negotiation as a callback.
627
625
  const versionNegotiator = ()=>{
628
626
  // Write a log message to show that we have started version negotiation.
629
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);
627
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);
630
628
  // remove the one-time error handler since no error was detected.
631
629
  this.socket.removeListener("error", rejector);
632
630
  // Build a version negotiation message.
633
- const versionMessage = (0, $c78f59d21170b7a6$export$2e2bcd8739ae039).buildRequestObject("server.version", [
631
+ const versionMessage = (0, $24139611f53a54b8$export$2e2bcd8739ae039).buildRequestObject("server.version", [
634
632
  this.application,
635
633
  this.version
636
634
  ], "versionNegotiation");
637
635
  // Define a function to wrap version validation as a function.
638
636
  const versionValidator = (version)=>{
639
637
  // Check if version negotiation failed.
640
- if ((0, $a192ea5a4eec42d4$export$e1f38ab2b4ebdde6)(version)) {
638
+ if ((0, $e83d2e7688025acd$export$e1f38ab2b4ebdde6)(version)) {
641
639
  // Disconnect from the host.
642
640
  this.disconnect(true);
643
641
  // Declare an error message.
644
642
  const errorMessage = "unsupported protocol version.";
645
643
  // Log the error.
646
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
644
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
647
645
  // Reject the connection with false since version negotiation failed.
648
646
  reject(errorMessage);
649
647
  } else if (version.protocol !== this.version && `${version.protocol}.0` !== this.version && `${version.protocol}.0.0` !== this.version) {
@@ -652,14 +650,14 @@ var $a58372b18a18806e$export$7516420eb880ab68;
652
650
  // Declare an error message.
653
651
  const errorMessage = `incompatible protocol version negotiated (${version.protocol} !== ${this.version}).`;
654
652
  // Log the error.
655
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
653
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
656
654
  // Reject the connection with false since version negotiation failed.
657
655
  reject(errorMessage);
658
656
  } else {
659
657
  // Write a log message.
660
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);
658
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);
661
659
  // Set connection status to connected
662
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED;
660
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED;
663
661
  // Emit a connect event now that the connection is usable.
664
662
  this.emit("connect");
665
663
  // Resolve the connection promise since we successfully connected and negotiated protocol version.
@@ -687,9 +685,9 @@ var $a58372b18a18806e$export$7516420eb880ab68;
687
685
  // If a reconnect timer is set, remove it
688
686
  await this.clearReconnectTimer();
689
687
  // Write a log message.
690
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Trying to reconnect to '${this.hostIdentifier}'..`);
688
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Trying to reconnect to '${this.hostIdentifier}'..`);
691
689
  // Set the status to reconnecting for more accurate log messages.
692
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).RECONNECTING;
690
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).RECONNECTING;
693
691
  // Destroy and recreate the socket to get a clean slate.
694
692
  this.destroySocket();
695
693
  this.createSocket();
@@ -732,13 +730,13 @@ var $a58372b18a18806e$export$7516420eb880ab68;
732
730
  * @returns true if successfully disconnected, or false if there was no connection.
733
731
  */ async disconnect(force = false, intentional = true) {
734
732
  // Return early when there is nothing to disconnect from
735
- if (this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED && !force) // Return false to indicate that there was nothing to disconnect from.
733
+ if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED && !force) // Return false to indicate that there was nothing to disconnect from.
736
734
  return false;
737
735
  // Update connection state if the disconnection is intentional.
738
736
  // NOTE: The state is meant to represent what the client is requesting, but
739
737
  // is used internally to handle visibility changes in browsers to ensure functional reconnection.
740
738
  if (intentional) // Set connection status to null to indicate tear-down is currently happening.
741
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTING;
739
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTING;
742
740
  // If a keep-alive timer is set, remove it.
743
741
  await this.clearKeepAliveTimer();
744
742
  // If a reconnect timer is set, remove it
@@ -791,7 +789,7 @@ var $a58372b18a18806e$export$7516420eb880ab68;
791
789
  // Set a new keep-alive timer.
792
790
  this.setupKeepAliveTimer();
793
791
  // Write the message to the network socket.
794
- return this.socket.write(message + (0, $c78f59d21170b7a6$export$2e2bcd8739ae039).statementDelimiter);
792
+ return this.socket.write(message + (0, $24139611f53a54b8$export$2e2bcd8739ae039).statementDelimiter);
795
793
  }
796
794
  // --- Event managers. --- //
797
795
  /**
@@ -801,14 +799,14 @@ var $a58372b18a18806e$export$7516420eb880ab68;
801
799
  // If we haven't received any data since we last sent data out..
802
800
  if (Number(this.lastReceivedTimestamp) < sentTimestamp) {
803
801
  // If this connection is already disconnected, we do not change anything
804
- if (this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED || this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTING) {
805
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Tried to verify already disconnected connection to '${this.hostIdentifier}'`);
802
+ if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED || this.status === (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTING) {
803
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Tried to verify already disconnected connection to '${this.hostIdentifier}'`);
806
804
  return;
807
805
  }
808
806
  // Remove the current keep-alive timer if it exists.
809
807
  this.clearKeepAliveTimer();
810
808
  // Write a notification to the logs.
811
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Connection to '${this.hostIdentifier}' timed out.`);
809
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Connection to '${this.hostIdentifier}' timed out.`);
812
810
  // Close the connection to avoid re-use.
813
811
  // NOTE: This initiates reconnection routines if the connection has not
814
812
  // been marked as intentionally disconnected.
@@ -837,21 +835,21 @@ var $a58372b18a18806e$export$7516420eb880ab68;
837
835
  // Remove the current keep-alive timer if it exists.
838
836
  this.clearKeepAliveTimer();
839
837
  // If this is a connection we're trying to tear down..
840
- if (this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTING) {
838
+ if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTING) {
841
839
  // If a reconnect timer is set, remove it.
842
840
  this.clearReconnectTimer();
843
841
  // Remove all event listeners
844
842
  this.removeAllListeners();
845
843
  // Mark the connection as disconnected.
846
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED;
844
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
847
845
  // Write a log message.
848
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Disconnected from '${this.hostIdentifier}'.`);
846
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Disconnected from '${this.hostIdentifier}'.`);
849
847
  } else {
850
848
  // If this is for an established connection..
851
- if (this.status === (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED) // Write a notification to the logs.
852
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.reconnectInterval / 1000} seconds.`);
849
+ if (this.status === (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) // Write a notification to the logs.
850
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.reconnectInterval / 1000} seconds.`);
853
851
  // Mark the connection as disconnected for now..
854
- this.status = (0, $a58372b18a18806e$export$7516420eb880ab68).DISCONNECTED;
852
+ this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
855
853
  // If we don't have a pending reconnection timer..
856
854
  if (!this.timers.reconnect) // Attempt to reconnect after one keep-alive duration.
857
855
  this.timers.reconnect = setTimeout(this.reconnect.bind(this), this.reconnectInterval);
@@ -868,21 +866,21 @@ var $a58372b18a18806e$export$7516420eb880ab68;
868
866
  return;
869
867
  // If the DNS lookup failed.
870
868
  if (error.code === "EAI_AGAIN") {
871
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Failed to look up DNS records for '${this.host}'.`);
869
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Failed to look up DNS records for '${this.host}'.`);
872
870
  return;
873
871
  }
874
872
  // If the connection timed out..
875
873
  if (error.code === "ETIMEDOUT") {
876
874
  // Log the provided timeout message.
877
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(error.message);
875
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(error.message);
878
876
  return;
879
877
  }
880
878
  // Log unknown error
881
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).errors(`Unknown network error ('${this.hostIdentifier}'): `, error);
879
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).errors(`Unknown network error ('${this.hostIdentifier}'): `, error);
882
880
  }
883
881
  }
884
882
  var // Export the connection.
885
- $1326c18f93f95fee$export$2e2bcd8739ae039 = $1326c18f93f95fee$var$ElectrumConnection;
883
+ $ff134c9a9e1f7361$export$2e2bcd8739ae039 = $ff134c9a9e1f7361$var$ElectrumConnection;
886
884
 
887
885
 
888
886
 
@@ -890,16 +888,16 @@ $1326c18f93f95fee$export$2e2bcd8739ae039 = $1326c18f93f95fee$var$ElectrumConnect
890
888
 
891
889
 
892
890
  // Acceptable parameter types for RPC messages
893
- const $7c0fb93e8eea922a$export$d73a2e87a509880 = function(message) {
891
+ const $abcb763a48577a1e$export$d73a2e87a509880 = function(message) {
894
892
  return "id" in message && "error" in message;
895
893
  };
896
- const $7c0fb93e8eea922a$export$81276773828ff315 = function(message) {
894
+ const $abcb763a48577a1e$export$81276773828ff315 = function(message) {
897
895
  return "id" in message && "result" in message;
898
896
  };
899
- const $7c0fb93e8eea922a$export$280de919a0cf6928 = function(message) {
897
+ const $abcb763a48577a1e$export$280de919a0cf6928 = function(message) {
900
898
  return !("id" in message) && "method" in message;
901
899
  };
902
- const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
900
+ const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
903
901
  return "id" in message && "method" in message;
904
902
  };
905
903
 
@@ -919,7 +917,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
919
917
  * @event ElectrumClient#notification
920
918
  */ /**
921
919
  * High-level Electrum client that lets applications send requests and subscribe to notification events from a server.
922
- */ class $620a18299ef8d6fd$var$ElectrumClient extends (0, $4QiMX$EventEmitter) {
920
+ */ class $558b46d3f899ced5$var$ElectrumClient extends (0, $dvphU$EventEmitter) {
923
921
  /**
924
922
  * Initializes an Electrum client.
925
923
  *
@@ -934,7 +932,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
934
932
  * @param {boolean} useBigInt whether to use bigint for numbers in json response.
935
933
  *
936
934
  * @throws {Error} if `version` is not a valid version string.
937
- */ constructor(application, version, host, port = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).PORT, scheme = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $5abc8fb342687c03$export$f019be48b3aacb1a).USE_BIG_INT){
935
+ */ constructor(application, version, host, port = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PORT, scheme = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TRANSPORT_SCHEME, timeout = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).TIMEOUT, pingInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).PING_INTERVAL, reconnectInterval = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).RECONNECT, useBigInt = (0, $d801b1f9b7fc3074$export$f019be48b3aacb1a).USE_BIG_INT){
938
936
  // Initialize the event emitter.
939
937
  super();
940
938
  this.application = application;
@@ -949,9 +947,9 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
949
947
  this.subscriptionMethods = {};
950
948
  this.requestId = 0;
951
949
  this.requestResolvers = {};
952
- this.connectionLock = new (0, $4QiMX$Mutex)();
950
+ this.connectionLock = new (0, $dvphU$Mutex)();
953
951
  // Set up a connection to an electrum server.
954
- this.connection = new (0, $1326c18f93f95fee$export$2e2bcd8739ae039)(application, version, host, port, scheme, timeout, pingInterval, reconnectInterval, useBigInt);
952
+ this.connection = new (0, $ff134c9a9e1f7361$export$2e2bcd8739ae039)(application, version, host, port, scheme, timeout, pingInterval, reconnectInterval, useBigInt);
955
953
  }
956
954
  /**
957
955
  * Connects to the remote server.
@@ -963,7 +961,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
963
961
  const unlock = await this.connectionLock.acquire();
964
962
  try {
965
963
  // If we are already connected, do not attempt to connect again.
966
- if (this.connection.status === (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED) return;
964
+ if (this.connection.status === (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) return;
967
965
  // Listen for parsed statements.
968
966
  this.connection.on("statement", this.response.bind(this));
969
967
  // Hook up resubscription on connection.
@@ -971,6 +969,9 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
971
969
  // Relay connect and disconnect events.
972
970
  this.connection.on("connect", this.emit.bind(this, "connected"));
973
971
  this.connection.on("disconnect", this.onConnectionDisconnect.bind(this));
972
+ // Hook up client metadata gathering functions.
973
+ this.connection.on("version", this.storeSoftwareVersion.bind(this));
974
+ this.connection.on("received", this.updateLastReceivedTimestamp.bind(this));
974
975
  // Relay error events.
975
976
  this.connection.on("error", this.emit.bind(this, "error"));
976
977
  // Connect with the server.
@@ -1020,14 +1021,14 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1020
1021
  * @returns a promise that resolves with the result of the method or an Error.
1021
1022
  */ async request(method, ...parameters) {
1022
1023
  // If we are not connected to a server..
1023
- if (this.connection.status !== (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED) // Reject the request with a disconnected error message.
1024
+ if (this.connection.status !== (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) // Reject the request with a disconnected error message.
1024
1025
  throw new Error(`Unable to send request to a disconnected server '${this.connection.host}'.`);
1025
1026
  // Increase the request ID by one.
1026
1027
  this.requestId += 1;
1027
1028
  // Store a copy of the request id.
1028
1029
  const id = this.requestId;
1029
1030
  // Format the arguments as an electrum request object.
1030
- const message = (0, $c78f59d21170b7a6$export$2e2bcd8739ae039).buildRequestObject(method, parameters, id);
1031
+ const message = (0, $24139611f53a54b8$export$2e2bcd8739ae039).buildRequestObject(method, parameters, id);
1031
1032
  // Define a function to wrap the request in a promise.
1032
1033
  const requestResolver = (resolve)=>{
1033
1034
  // Add a request resolver for this promise to the list of requests.
@@ -1042,7 +1043,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1042
1043
  this.connection.send(message);
1043
1044
  };
1044
1045
  // Write a log message.
1045
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).network(`Sending request '${method}' to '${this.connection.host}'`);
1046
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).network(`Sending request '${method}' to '${this.connection.host}'`);
1046
1047
  // return a promise to deliver results later.
1047
1048
  return new Promise(requestResolver);
1048
1049
  }
@@ -1074,6 +1075,8 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1074
1075
  };
1075
1076
  // Manually emit an event for the initial response.
1076
1077
  this.emit("notification", notification);
1078
+ // Try to update the chain height.
1079
+ this.updateChainHeightFromHeadersNotifications(notification);
1077
1080
  }
1078
1081
  /**
1079
1082
  * Unsubscribes to the method at the server and removes any callback functions
@@ -1087,7 +1090,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1087
1090
  * @returns a promise resolving when the subscription is removed.
1088
1091
  */ async unsubscribe(method, ...parameters) {
1089
1092
  // Throw an error if the client is disconnected.
1090
- if (this.connection.status !== (0, $a58372b18a18806e$export$7516420eb880ab68).CONNECTED) throw new Error(`Unable to send unsubscribe request to a disconnected server '${this.connection.host}'.`);
1093
+ if (this.connection.status !== (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) throw new Error(`Unable to send unsubscribe request to a disconnected server '${this.connection.host}'.`);
1091
1094
  // If this method has no subscriptions..
1092
1095
  if (!this.subscriptionMethods[method]) // Reject this promise with an explanation.
1093
1096
  throw new Error(`Cannot unsubscribe from '${method}' since the method has no subscriptions.`);
@@ -1102,7 +1105,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1102
1105
  // NOTE: As a convenience we allow users to define the method as the subscribe or unsubscribe version.
1103
1106
  await this.request(method.replace(".subscribe", ".unsubscribe"), ...parameters);
1104
1107
  // Write a log message.
1105
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);
1108
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);
1106
1109
  }
1107
1110
  /**
1108
1111
  * Restores existing subscriptions without updating status or triggering manual callbacks.
@@ -1114,7 +1117,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1114
1117
  * @ignore
1115
1118
  */ async resubscribeOnConnect() {
1116
1119
  // Write a log message.
1117
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).client(`Connected to '${this.connection.hostIdentifier}'.`);
1120
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Connected to '${this.connection.hostIdentifier}'.`);
1118
1121
  // Initialize an empty list of resubscription promises.
1119
1122
  const resubscriptionPromises = [];
1120
1123
  // For each method we have a subscription for..
@@ -1130,7 +1133,7 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1130
1133
  await Promise.all(resubscriptionPromises);
1131
1134
  }
1132
1135
  // Write a log message if there was any subscriptions to restore.
1133
- if (resubscriptionPromises.length > 0) (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.connection.hostIdentifier}'`);
1136
+ if (resubscriptionPromises.length > 0) (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.connection.hostIdentifier}'`);
1134
1137
  }
1135
1138
  /**
1136
1139
  * Parser messages from the remote server to resolve request promises and emit subscription events.
@@ -1141,11 +1144,13 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1141
1144
  * @ignore
1142
1145
  */ response(message) {
1143
1146
  // If the received message is a notification, we forward it to all event listeners
1144
- if ((0, $7c0fb93e8eea922a$export$280de919a0cf6928)(message)) {
1147
+ if ((0, $abcb763a48577a1e$export$280de919a0cf6928)(message)) {
1145
1148
  // Write a log message.
1146
- (0, $ef5ba40c8abe5a13$export$2e2bcd8739ae039).client(`Received notification for '${message.method}' from '${this.connection.host}'`);
1149
+ (0, $623a31cc1663a627$export$2e2bcd8739ae039).client(`Received notification for '${message.method}' from '${this.connection.host}'`);
1147
1150
  // Forward the message content to all event listeners.
1148
1151
  this.emit("notification", message);
1152
+ // Try to update the chain height.
1153
+ this.updateChainHeightFromHeadersNotifications(message);
1149
1154
  // Return since it does not have an associated request resolver
1150
1155
  return;
1151
1156
  }
@@ -1160,11 +1165,15 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1160
1165
  // Remove the promise from the request list.
1161
1166
  delete this.requestResolvers[message.id];
1162
1167
  // If the message contains an error..
1163
- if ((0, $7c0fb93e8eea922a$export$d73a2e87a509880)(message)) // Forward the message error to the request resolver and omit the `result` parameter.
1168
+ if ((0, $abcb763a48577a1e$export$d73a2e87a509880)(message)) // Forward the message error to the request resolver and omit the `result` parameter.
1164
1169
  requestResolver(new Error(message.error.message));
1165
- else // Forward the message content to the request resolver and omit the `error` parameter
1166
- // (by setting it to undefined).
1167
- requestResolver(undefined, message.result);
1170
+ else {
1171
+ // Forward the message content to the request resolver and omit the `error` parameter
1172
+ // (by setting it to undefined).
1173
+ requestResolver(undefined, message.result);
1174
+ // Attempt to extract genesis hash from feature requests.
1175
+ this.storeGenesisHashFromFeaturesResponse(message);
1176
+ }
1168
1177
  }
1169
1178
  /**
1170
1179
  * Callback function that is called when connection to the Electrum server is lost.
@@ -1184,9 +1193,46 @@ const $7c0fb93e8eea922a$export$94e3360fcddccc76 = function(message) {
1184
1193
  delete this.requestResolvers[resolverId];
1185
1194
  }
1186
1195
  }
1196
+ /**
1197
+ * Stores the server provider software version field on successful version negotiation.
1198
+ */ async storeSoftwareVersion(versionStatement) {
1199
+ // TODO: handle failed version negotiation better.
1200
+ if (versionStatement.error) // Do nothing.
1201
+ return;
1202
+ // Store the software version.
1203
+ this.software = versionStatement.software;
1204
+ }
1205
+ /**
1206
+ * Updates the last received timestamp.
1207
+ *
1208
+ * @ignore
1209
+ */ async updateLastReceivedTimestamp() {
1210
+ // Update the timestamp for when we last received data.
1211
+ this.lastReceivedTimestamp = Date.now();
1212
+ }
1213
+ /**
1214
+ * Checks if the provided message is a response to a headers subscription,
1215
+ * and if so updates the locally stored chain height value for this client.
1216
+ *
1217
+ * @ignore
1218
+ */ async updateChainHeightFromHeadersNotifications(message) {
1219
+ // If the message is a notification for a new chain height..
1220
+ if (message.method === "blockchain.headers.subscribe") // ..also store the updated chain height locally.
1221
+ this.chainHeight = message.params[0].height;
1222
+ }
1223
+ /**
1224
+ * Checks if the provided message is a response to a server.features request,
1225
+ * and if so stores the genesis hash for this client locally.
1226
+ *
1227
+ * @ignore
1228
+ */ async storeGenesisHashFromFeaturesResponse(message) {
1229
+ // If the message is a response to a features request..
1230
+ if (message.result.genesis_hash) // ..store the genesis hash locally.
1231
+ this.genesisHash = message.result.genesis_hash;
1232
+ }
1187
1233
  }
1188
1234
  var // Export the client.
1189
- $620a18299ef8d6fd$export$2e2bcd8739ae039 = $620a18299ef8d6fd$var$ElectrumClient;
1235
+ $558b46d3f899ced5$export$2e2bcd8739ae039 = $558b46d3f899ced5$var$ElectrumClient;
1190
1236
 
1191
1237
 
1192
1238
 
@@ -1194,5 +1240,5 @@ $620a18299ef8d6fd$export$2e2bcd8739ae039 = $620a18299ef8d6fd$var$ElectrumClient;
1194
1240
 
1195
1241
 
1196
1242
 
1197
- export {$620a18299ef8d6fd$export$2e2bcd8739ae039 as ElectrumClient, $a192ea5a4eec42d4$export$e1f38ab2b4ebdde6 as isVersionRejected, $a192ea5a4eec42d4$export$9598f0c76aa41d73 as isVersionNegotiated, $5abc8fb342687c03$export$d048df559e6d3842 as ElectrumTransport, $5abc8fb342687c03$export$f019be48b3aacb1a as DefaultParameters, $a58372b18a18806e$export$c4f81c6d30ca200f as ClientState, $a58372b18a18806e$export$7516420eb880ab68 as ConnectionStatus};
1243
+ export {$558b46d3f899ced5$export$2e2bcd8739ae039 as ElectrumClient, $e83d2e7688025acd$export$e1f38ab2b4ebdde6 as isVersionRejected, $e83d2e7688025acd$export$9598f0c76aa41d73 as isVersionNegotiated, $d801b1f9b7fc3074$export$d048df559e6d3842 as ElectrumTransport, $d801b1f9b7fc3074$export$f019be48b3aacb1a as DefaultParameters, $db7c797e63383364$export$c4f81c6d30ca200f as ClientState, $db7c797e63383364$export$7516420eb880ab68 as ConnectionStatus};
1198
1244
  //# sourceMappingURL=index.mjs.map