@electrum-cash/network 4.1.3 → 4.1.4-development.11641455551
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.d.ts.map +1 -1
- package/dist/index.mjs +72 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AACA,oBAA2B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AAGrE,qBAA4B,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAGnD;IAEC,OAAO,EAAE,MAAM,CAAC;CAChB;AAGD,yBAAiC,SAAQ,OAAO;IAE/C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB;AAWD,sBAA8B,SAAQ,OAAO;IAE5C,EAAE,EAAE,aAAa,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf;AAED;IAEC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;CACX;AAGD,0BAAkC,SAAQ,OAAO;IAEhD,EAAE,EAAE,aAAa,CAAC;IAClB,KAAK,EAAE,QAAQ,CAAC;CAChB;AAGD,mBAA0B,gBAAgB,GAAG,YAAY,GAAG,eAAe,CAAC;AE9C5E;;GAEG;AACH;IAEC,2GAA2G;IAC3G,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,iEAAiE;IACjE,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAE7C,yEAAyE;IACzE,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAEpC,qFAAqF;IACrF,qCAAqC,CAAC,EAAE,MAAM,CAAC;IAE/C,8IAA8I;IAC9I,gCAAgC,CAAC,EAAE,OAAO,CAAC;IAE3C,2DAA2D;IAC3D,kCAAkC,CAAC,EAAE,OAAO,CAAC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AAgB,aAAa,EAAE,EAAE,CAAC;IAClC,SAAgB,YAAY,EAAE,EAAE,CAAC;IACjC,SAAgB,YAAY,EAAE,EAAE,CAAC;IACjC,SAAgB,YAAY,EAAE,CAAE,eAAe,CAAE,CAAC;IAClD,SAAgB,KAAK,EAAE,CAAE,KAAK,CAAE,CAAC;CACjC","sources":["source/source/rpc-interfaces.ts","source/source/electrum-protocol.ts","source/source/interfaces.ts","source/source/enums.ts","source/source/electrum-connection.ts","source/source/constants.ts","source/source/electrum-client.ts","source/source/index.ts","source/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './enums';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ class $24139611f53a54b8$export$5d955335434540c6 {
|
|
|
43
43
|
*
|
|
44
44
|
* @returns the delimiter used by Electrum to separate statements.
|
|
45
45
|
*/ static get statementDelimiter() {
|
|
46
|
-
return
|
|
46
|
+
return '\n';
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -53,25 +53,25 @@ var $e83d2e7688025acd$exports = {};
|
|
|
53
53
|
$parcel$export($e83d2e7688025acd$exports, "isVersionRejected", () => $e83d2e7688025acd$export$e1f38ab2b4ebdde6);
|
|
54
54
|
$parcel$export($e83d2e7688025acd$exports, "isVersionNegotiated", () => $e83d2e7688025acd$export$9598f0c76aa41d73);
|
|
55
55
|
const $e83d2e7688025acd$export$e1f38ab2b4ebdde6 = function(object) {
|
|
56
|
-
return
|
|
56
|
+
return 'error' in object;
|
|
57
57
|
};
|
|
58
58
|
const $e83d2e7688025acd$export$9598f0c76aa41d73 = function(object) {
|
|
59
|
-
return
|
|
59
|
+
return 'software' in object && 'protocol' in object;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
// Acceptable parameter types for RPC messages
|
|
64
64
|
const $abcb763a48577a1e$export$d73a2e87a509880 = function(message) {
|
|
65
|
-
return
|
|
65
|
+
return 'id' in message && 'error' in message;
|
|
66
66
|
};
|
|
67
67
|
const $abcb763a48577a1e$export$81276773828ff315 = function(message) {
|
|
68
|
-
return
|
|
68
|
+
return 'id' in message && 'result' in message;
|
|
69
69
|
};
|
|
70
70
|
const $abcb763a48577a1e$export$280de919a0cf6928 = function(message) {
|
|
71
|
-
return !(
|
|
71
|
+
return !('id' in message) && 'method' in message;
|
|
72
72
|
};
|
|
73
73
|
const $abcb763a48577a1e$export$94e3360fcddccc76 = function(message) {
|
|
74
|
-
return
|
|
74
|
+
return 'id' in message && 'method' in message;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
|
|
@@ -88,14 +88,14 @@ $parcel$export($db7c797e63383364$exports, "ConnectionStatus", () => $db7c797e633
|
|
|
88
88
|
* @property {2} DISCONNECTING The connection is disconnecting.
|
|
89
89
|
* @property {3} CONNECTING The connection is connecting.
|
|
90
90
|
* @property {4} RECONNECTING The connection is restarting.
|
|
91
|
-
*/ var $db7c797e63383364$export$7516420eb880ab68
|
|
92
|
-
(function(ConnectionStatus) {
|
|
91
|
+
*/ var $db7c797e63383364$export$7516420eb880ab68 = /*#__PURE__*/ function(ConnectionStatus) {
|
|
93
92
|
ConnectionStatus[ConnectionStatus["DISCONNECTED"] = 0] = "DISCONNECTED";
|
|
94
93
|
ConnectionStatus[ConnectionStatus["CONNECTED"] = 1] = "CONNECTED";
|
|
95
94
|
ConnectionStatus[ConnectionStatus["DISCONNECTING"] = 2] = "DISCONNECTING";
|
|
96
95
|
ConnectionStatus[ConnectionStatus["CONNECTING"] = 3] = "CONNECTING";
|
|
97
96
|
ConnectionStatus[ConnectionStatus["RECONNECTING"] = 4] = "RECONNECTING";
|
|
98
|
-
|
|
97
|
+
return ConnectionStatus;
|
|
98
|
+
}({});
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
|
|
@@ -111,33 +111,26 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
111
111
|
* @throws {Error} if `version` is not a valid version string.
|
|
112
112
|
*/ constructor(application, version, socketOrHostname, options){
|
|
113
113
|
// Initialize the event emitter.
|
|
114
|
-
super();
|
|
115
|
-
this.application = application;
|
|
116
|
-
this.version = version;
|
|
117
|
-
this.socketOrHostname = socketOrHostname;
|
|
118
|
-
this.options = options;
|
|
119
|
-
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
|
|
120
|
-
this.verifications = [];
|
|
121
|
-
this.messageBuffer = "";
|
|
114
|
+
super(), this.application = application, this.version = version, this.socketOrHostname = socketOrHostname, this.options = options, this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED, this.verifications = [], this.messageBuffer = '';
|
|
122
115
|
// Check if the provided version is a valid version number.
|
|
123
116
|
if (!(0, $24139611f53a54b8$export$5d955335434540c6).versionRegexp.test(version)) // Throw an error since the version number was not valid.
|
|
124
117
|
throw new Error(`Provided version string (${version}) is not a valid protocol version number.`);
|
|
125
118
|
// If a hostname was provided..
|
|
126
|
-
if (typeof socketOrHostname ===
|
|
119
|
+
if (typeof socketOrHostname === 'string') // Use a web socket with default parameters.
|
|
127
120
|
this.socket = new (0, $dvphU$ElectrumWebSocket)(socketOrHostname);
|
|
128
121
|
else // Use the provided socket.
|
|
129
122
|
this.socket = socketOrHostname;
|
|
130
123
|
// Set up handlers for connection and disconnection.
|
|
131
|
-
this.socket.on(
|
|
132
|
-
this.socket.on(
|
|
124
|
+
this.socket.on('connected', this.onSocketConnect.bind(this));
|
|
125
|
+
this.socket.on('disconnected', this.onSocketDisconnect.bind(this));
|
|
133
126
|
// Set up handler for incoming data.
|
|
134
|
-
this.socket.on(
|
|
127
|
+
this.socket.on('data', this.parseMessageChunk.bind(this));
|
|
135
128
|
// Handle visibility changes when run in a browser environment (if not explicitly disabled).
|
|
136
|
-
if (typeof document !==
|
|
129
|
+
if (typeof document !== 'undefined' && !this.options.disableBrowserVisibilityHandling) document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
137
130
|
// Handle network connection changes when run in a browser environment (if not explicitly disabled).
|
|
138
|
-
if (typeof window !==
|
|
139
|
-
window.addEventListener(
|
|
140
|
-
window.addEventListener(
|
|
131
|
+
if (typeof window !== 'undefined' && !this.options.disableBrowserConnectivityHandling) {
|
|
132
|
+
window.addEventListener('online', this.handleNetworkChange.bind(this));
|
|
133
|
+
window.addEventListener('offline', this.handleNetworkChange.bind(this));
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
136
|
// Expose hostIdentifier from the socket.
|
|
@@ -158,7 +151,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
158
151
|
// Update the timestamp for when we last received data.
|
|
159
152
|
this.lastReceivedTimestamp = Date.now();
|
|
160
153
|
// Emit a notification indicating that the connection has received data.
|
|
161
|
-
this.emit(
|
|
154
|
+
this.emit('received');
|
|
162
155
|
// Clear and remove all verification timers.
|
|
163
156
|
this.verifications.forEach((timer)=>clearTimeout(timer));
|
|
164
157
|
this.verifications.length = 0;
|
|
@@ -185,20 +178,20 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
185
178
|
// If the current statement is a subscription notification..
|
|
186
179
|
if ((0, $abcb763a48577a1e$export$280de919a0cf6928)(currentStatement)) {
|
|
187
180
|
// Emit the notification for handling higher up in the stack.
|
|
188
|
-
this.emit(
|
|
181
|
+
this.emit('response', currentStatement);
|
|
189
182
|
continue;
|
|
190
183
|
}
|
|
191
184
|
// If the current statement is a version negotiation response..
|
|
192
|
-
if (currentStatement.id ===
|
|
185
|
+
if (currentStatement.id === 'versionNegotiation') {
|
|
193
186
|
if ((0, $abcb763a48577a1e$export$d73a2e87a509880)(currentStatement)) // Then emit a failed version negotiation response signal.
|
|
194
|
-
this.emit(
|
|
187
|
+
this.emit('version', {
|
|
195
188
|
error: currentStatement.error
|
|
196
189
|
});
|
|
197
190
|
else {
|
|
198
191
|
// Extract the software and protocol version reported.
|
|
199
192
|
const [software, protocol] = currentStatement.result;
|
|
200
193
|
// Emit a successful version negotiation response signal.
|
|
201
|
-
this.emit(
|
|
194
|
+
this.emit('version', {
|
|
202
195
|
software: software,
|
|
203
196
|
protocol: protocol
|
|
204
197
|
});
|
|
@@ -206,13 +199,13 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
206
199
|
continue;
|
|
207
200
|
}
|
|
208
201
|
// If the current statement is a keep-alive response..
|
|
209
|
-
if (currentStatement.id ===
|
|
202
|
+
if (currentStatement.id === 'keepAlive') continue;
|
|
210
203
|
// Emit the statements for handling higher up in the stack.
|
|
211
|
-
this.emit(
|
|
204
|
+
this.emit('response', currentStatement);
|
|
212
205
|
}
|
|
213
206
|
}
|
|
214
207
|
// Store the remaining statement as the current message buffer.
|
|
215
|
-
this.messageBuffer = statementParts.shift() ||
|
|
208
|
+
this.messageBuffer = statementParts.shift() || '';
|
|
216
209
|
}
|
|
217
210
|
}
|
|
218
211
|
/**
|
|
@@ -224,7 +217,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
224
217
|
// Write a log message.
|
|
225
218
|
(0, $dvphU$electrumcashdebuglogs).ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);
|
|
226
219
|
// Craft a keep-alive message.
|
|
227
|
-
const message = (0, $24139611f53a54b8$export$5d955335434540c6).buildRequestObject(
|
|
220
|
+
const message = (0, $24139611f53a54b8$export$5d955335434540c6).buildRequestObject('server.ping', [], 'keepAlive');
|
|
228
221
|
// Send the keep-alive message.
|
|
229
222
|
const status = this.send(message);
|
|
230
223
|
// Return the ping status.
|
|
@@ -241,31 +234,31 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
241
234
|
// Indicate that the connection is connecting
|
|
242
235
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTING;
|
|
243
236
|
// Emit a connect event now that the connection is being set up.
|
|
244
|
-
this.emit(
|
|
237
|
+
this.emit('connecting');
|
|
245
238
|
// Define a function to wrap connection as a promise.
|
|
246
239
|
const connectionResolver = (resolve, reject)=>{
|
|
247
240
|
const rejector = (error)=>{
|
|
248
241
|
// Set the status back to disconnected
|
|
249
242
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
|
|
250
243
|
// Emit a connect event indicating that we failed to connect.
|
|
251
|
-
this.emit(
|
|
244
|
+
this.emit('disconnected');
|
|
252
245
|
// Reject with the error as reason
|
|
253
246
|
reject(error);
|
|
254
247
|
};
|
|
255
248
|
// Replace previous error handlers to reject the promise on failure.
|
|
256
|
-
this.socket.removeAllListeners(
|
|
257
|
-
this.socket.once(
|
|
249
|
+
this.socket.removeAllListeners('error');
|
|
250
|
+
this.socket.once('error', rejector);
|
|
258
251
|
// Define a function to wrap version negotiation as a callback.
|
|
259
252
|
const versionNegotiator = ()=>{
|
|
260
253
|
// Write a log message to show that we have started version negotiation.
|
|
261
254
|
(0, $dvphU$electrumcashdebuglogs).network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);
|
|
262
255
|
// remove the one-time error handler since no error was detected.
|
|
263
|
-
this.socket.removeListener(
|
|
256
|
+
this.socket.removeListener('error', rejector);
|
|
264
257
|
// Build a version negotiation message.
|
|
265
|
-
const versionMessage = (0, $24139611f53a54b8$export$5d955335434540c6).buildRequestObject(
|
|
258
|
+
const versionMessage = (0, $24139611f53a54b8$export$5d955335434540c6).buildRequestObject('server.version', [
|
|
266
259
|
this.application,
|
|
267
260
|
this.version
|
|
268
|
-
],
|
|
261
|
+
], 'versionNegotiation');
|
|
269
262
|
// Define a function to wrap version validation as a function.
|
|
270
263
|
const versionValidator = (version)=>{
|
|
271
264
|
// Check if version negotiation failed.
|
|
@@ -273,7 +266,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
273
266
|
// Disconnect from the host.
|
|
274
267
|
this.disconnect(true);
|
|
275
268
|
// Declare an error message.
|
|
276
|
-
const errorMessage =
|
|
269
|
+
const errorMessage = 'unsupported protocol version.';
|
|
277
270
|
// Log the error.
|
|
278
271
|
(0, $dvphU$electrumcashdebuglogs).errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);
|
|
279
272
|
// Reject the connection with false since version negotiation failed.
|
|
@@ -293,20 +286,20 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
293
286
|
// Set connection status to connected
|
|
294
287
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED;
|
|
295
288
|
// Emit a connect event now that the connection is usable.
|
|
296
|
-
this.emit(
|
|
289
|
+
this.emit('connected');
|
|
297
290
|
// Resolve the connection promise since we successfully connected and negotiated protocol version.
|
|
298
291
|
resolve();
|
|
299
292
|
}
|
|
300
293
|
};
|
|
301
294
|
// Listen for version negotiation once.
|
|
302
|
-
this.once(
|
|
295
|
+
this.once('version', versionValidator);
|
|
303
296
|
// Send the version negotiation message.
|
|
304
297
|
this.send(versionMessage);
|
|
305
298
|
};
|
|
306
299
|
// Prepare the version negotiation.
|
|
307
|
-
this.socket.once(
|
|
300
|
+
this.socket.once('connected', versionNegotiator);
|
|
308
301
|
// Set up handler for network errors.
|
|
309
|
-
this.socket.on(
|
|
302
|
+
this.socket.on('error', this.onSocketError.bind(this));
|
|
310
303
|
// Connect to the server.
|
|
311
304
|
this.socket.connect();
|
|
312
305
|
};
|
|
@@ -323,7 +316,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
323
316
|
// Set the status to reconnecting for more accurate log messages.
|
|
324
317
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).RECONNECTING;
|
|
325
318
|
// Emit a connect event now that the connection is usable.
|
|
326
|
-
this.emit(
|
|
319
|
+
this.emit('reconnecting');
|
|
327
320
|
// Disconnect the underlying socket.
|
|
328
321
|
this.socket.disconnect();
|
|
329
322
|
try {
|
|
@@ -373,14 +366,14 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
373
366
|
if (intentional) // Set connection status to null to indicate tear-down is currently happening.
|
|
374
367
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTING;
|
|
375
368
|
// Emit a connect event to indicate that we are disconnecting.
|
|
376
|
-
this.emit(
|
|
369
|
+
this.emit('disconnecting');
|
|
377
370
|
// If a keep-alive timer is set, remove it.
|
|
378
371
|
await this.clearKeepAliveTimer();
|
|
379
372
|
// If a reconnect timer is set, remove it
|
|
380
373
|
await this.clearReconnectTimer();
|
|
381
374
|
const disconnectResolver = (resolve)=>{
|
|
382
375
|
// Resolve to true after the connection emits a disconnect
|
|
383
|
-
this.once(
|
|
376
|
+
this.once('disconnected', ()=>resolve(true));
|
|
384
377
|
// Close the connection on the socket level.
|
|
385
378
|
this.socket.disconnect();
|
|
386
379
|
};
|
|
@@ -397,7 +390,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
397
390
|
* When available, we make use of this to fail early to provide a better user experience.
|
|
398
391
|
*/ async handleNetworkChange() {
|
|
399
392
|
// Do nothing if we do not have the navigator available.
|
|
400
|
-
if (typeof window.navigator ===
|
|
393
|
+
if (typeof window.navigator === 'undefined') return;
|
|
401
394
|
// Attempt to reconnect to the network now that we may be online again.
|
|
402
395
|
if (window.navigator.onLine === true) this.reconnect();
|
|
403
396
|
// Disconnected from the network so that cleanup can happen while we're offline.
|
|
@@ -419,13 +412,13 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
419
412
|
* and make the behavior consistent across browsers.
|
|
420
413
|
*/ async handleVisibilityChange() {
|
|
421
414
|
// Disconnect when application is removed from focus.
|
|
422
|
-
if (document.visibilityState ===
|
|
415
|
+
if (document.visibilityState === 'hidden') {
|
|
423
416
|
const forceDisconnect = true;
|
|
424
417
|
const isIntentional = true;
|
|
425
418
|
this.disconnect(forceDisconnect, isIntentional);
|
|
426
419
|
}
|
|
427
420
|
// Reconnect when application is returned to focus.
|
|
428
|
-
if (document.visibilityState ===
|
|
421
|
+
if (document.visibilityState === 'visible') this.reconnect();
|
|
429
422
|
}
|
|
430
423
|
/**
|
|
431
424
|
* Sends an arbitrary message to the server.
|
|
@@ -478,9 +471,9 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
478
471
|
// Set up the initial keep-alive timer.
|
|
479
472
|
this.setupKeepAliveTimer();
|
|
480
473
|
// Clear all temporary error listeners.
|
|
481
|
-
this.socket.removeAllListeners(
|
|
474
|
+
this.socket.removeAllListeners('error');
|
|
482
475
|
// Set up handler for network errors.
|
|
483
|
-
this.socket.on(
|
|
476
|
+
this.socket.on('error', this.onSocketError.bind(this));
|
|
484
477
|
}
|
|
485
478
|
/**
|
|
486
479
|
* Updates the connection status when a connection is ended.
|
|
@@ -492,7 +485,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
492
485
|
// Mark the connection as disconnected.
|
|
493
486
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
|
|
494
487
|
// Send a disconnect signal higher up the stack.
|
|
495
|
-
this.emit(
|
|
488
|
+
this.emit('disconnected');
|
|
496
489
|
// If a reconnect timer is set, remove it.
|
|
497
490
|
this.clearReconnectTimer();
|
|
498
491
|
// Remove all event listeners
|
|
@@ -506,7 +499,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
506
499
|
// Mark the connection as disconnected for now..
|
|
507
500
|
this.status = (0, $db7c797e63383364$export$7516420eb880ab68).DISCONNECTED;
|
|
508
501
|
// Send a disconnect signal higher up the stack.
|
|
509
|
-
this.emit(
|
|
502
|
+
this.emit('disconnected');
|
|
510
503
|
// If we don't have a pending reconnection timer..
|
|
511
504
|
if (!this.reconnectTimer) // Attempt to reconnect after one keep-alive duration.
|
|
512
505
|
this.reconnectTimer = setTimeout(this.reconnect.bind(this), this.options.reconnectAfterMilliSeconds);
|
|
@@ -519,7 +512,7 @@ class $ff134c9a9e1f7361$export$de0f57fc22079b5e extends (0, $dvphU$EventEmitter)
|
|
|
519
512
|
// NOTE: When using WSS, the error event explicitly
|
|
520
513
|
// only allows to send a "simple" event without data.
|
|
521
514
|
// https://stackoverflow.com/a/18804298
|
|
522
|
-
if (typeof error ===
|
|
515
|
+
if (typeof error === 'undefined') // Do nothing, and instead rely on the socket disconnect event for further information.
|
|
523
516
|
return;
|
|
524
517
|
// Log the error, as there is nothing we can do to actually handle it.
|
|
525
518
|
(0, $dvphU$electrumcashdebuglogs).errors(`Network error ('${this.hostIdentifier}'): `, error);
|
|
@@ -568,15 +561,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
568
561
|
* @throws {Error} if `version` is not a valid version string.
|
|
569
562
|
*/ constructor(application, version, socketOrHostname, options = {}){
|
|
570
563
|
// Initialize the event emitter.
|
|
571
|
-
super();
|
|
572
|
-
this.application = application;
|
|
573
|
-
this.version = version;
|
|
574
|
-
this.socketOrHostname = socketOrHostname;
|
|
575
|
-
this.options = options;
|
|
576
|
-
this.subscriptionMethods = {};
|
|
577
|
-
this.requestId = 0;
|
|
578
|
-
this.requestResolvers = {};
|
|
579
|
-
this.connectionLock = new (0, $dvphU$Mutex)();
|
|
564
|
+
super(), this.application = application, this.version = version, this.socketOrHostname = socketOrHostname, this.options = options, this.subscriptionMethods = {}, this.requestId = 0, this.requestResolvers = {}, this.connectionLock = new (0, $dvphU$Mutex)();
|
|
580
565
|
// Update default options with the provided values.
|
|
581
566
|
const networkOptions = {
|
|
582
567
|
...(0, $d801b1f9b7fc3074$export$5ba3a4134d0d751d),
|
|
@@ -605,19 +590,19 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
605
590
|
// If we are already connected, do not attempt to connect again.
|
|
606
591
|
if (this.connection.status === (0, $db7c797e63383364$export$7516420eb880ab68).CONNECTED) return;
|
|
607
592
|
// Listen for parsed statements.
|
|
608
|
-
this.connection.on(
|
|
593
|
+
this.connection.on('response', this.response.bind(this));
|
|
609
594
|
// Hook up handles for the connected and disconnected events.
|
|
610
|
-
this.connection.on(
|
|
611
|
-
this.connection.on(
|
|
595
|
+
this.connection.on('connected', this.resubscribeOnConnect.bind(this));
|
|
596
|
+
this.connection.on('disconnected', this.onConnectionDisconnect.bind(this));
|
|
612
597
|
// Relay connecting and reconnecting events.
|
|
613
|
-
this.connection.on(
|
|
614
|
-
this.connection.on(
|
|
615
|
-
this.connection.on(
|
|
598
|
+
this.connection.on('connecting', this.handleConnectionStatusChanges.bind(this, 'connecting'));
|
|
599
|
+
this.connection.on('disconnecting', this.handleConnectionStatusChanges.bind(this, 'disconnecting'));
|
|
600
|
+
this.connection.on('reconnecting', this.handleConnectionStatusChanges.bind(this, 'reconnecting'));
|
|
616
601
|
// Hook up client metadata gathering functions.
|
|
617
|
-
this.connection.on(
|
|
618
|
-
this.connection.on(
|
|
602
|
+
this.connection.on('version', this.storeSoftwareVersion.bind(this));
|
|
603
|
+
this.connection.on('received', this.updateLastReceivedTimestamp.bind(this));
|
|
619
604
|
// Relay error events.
|
|
620
|
-
this.connection.on(
|
|
605
|
+
this.connection.on('error', this.emit.bind(this, 'error'));
|
|
621
606
|
// Connect with the server.
|
|
622
607
|
await this.connection.connect();
|
|
623
608
|
} finally{
|
|
@@ -698,10 +683,10 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
698
683
|
if (requestData instanceof Error) throw requestData;
|
|
699
684
|
// If the request returned more than one data point..
|
|
700
685
|
if (Array.isArray(requestData)) // .. throw an error, as this breaks our expectation for subscriptions.
|
|
701
|
-
throw new Error(
|
|
686
|
+
throw new Error('Subscription request returned an more than one data point.');
|
|
702
687
|
// Construct a notification structure to package the initial result as a notification.
|
|
703
688
|
const notification = {
|
|
704
|
-
jsonrpc:
|
|
689
|
+
jsonrpc: '2.0',
|
|
705
690
|
method: method,
|
|
706
691
|
params: [
|
|
707
692
|
...parameters,
|
|
@@ -709,7 +694,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
709
694
|
]
|
|
710
695
|
};
|
|
711
696
|
// Manually emit an event for the initial response.
|
|
712
|
-
this.emit(
|
|
697
|
+
this.emit('notification', notification);
|
|
713
698
|
// Try to update the chain height.
|
|
714
699
|
this.updateChainHeightFromHeadersNotifications(notification);
|
|
715
700
|
}
|
|
@@ -738,7 +723,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
738
723
|
this.subscriptionMethods[method].delete(subscriptionParameters);
|
|
739
724
|
// Send unsubscription request to the server
|
|
740
725
|
// NOTE: As a convenience we allow users to define the method as the subscribe or unsubscribe version.
|
|
741
|
-
await this.request(method.replace(
|
|
726
|
+
await this.request(method.replace('.subscribe', '.unsubscribe'), ...parameters);
|
|
742
727
|
// Write a log message.
|
|
743
728
|
(0, $dvphU$electrumcashdebuglogs).client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);
|
|
744
729
|
}
|
|
@@ -754,7 +739,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
754
739
|
// Write a log message.
|
|
755
740
|
(0, $dvphU$electrumcashdebuglogs).client(`Connected to '${this.hostIdentifier}'.`);
|
|
756
741
|
// Synchronize with the underlying connection status.
|
|
757
|
-
this.handleConnectionStatusChanges(
|
|
742
|
+
this.handleConnectionStatusChanges('connected');
|
|
758
743
|
// Initialize an empty list of resubscription promises.
|
|
759
744
|
const resubscriptionPromises = [];
|
|
760
745
|
// For each method we have a subscription for..
|
|
@@ -785,7 +770,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
785
770
|
// Write a log message.
|
|
786
771
|
(0, $dvphU$electrumcashdebuglogs).client(`Received notification for '${message.method}' from '${this.hostIdentifier}'`);
|
|
787
772
|
// Forward the message content to all event listeners.
|
|
788
|
-
this.emit(
|
|
773
|
+
this.emit('notification', message);
|
|
789
774
|
// Try to update the chain height.
|
|
790
775
|
this.updateChainHeightFromHeadersNotifications(message);
|
|
791
776
|
// Return since it does not have an associated request resolver
|
|
@@ -793,7 +778,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
793
778
|
}
|
|
794
779
|
// If the response ID is null we cannot use it to index our request resolvers
|
|
795
780
|
if (message.id === null) // Throw an internal error, this should not happen.
|
|
796
|
-
throw new Error(
|
|
781
|
+
throw new Error('Internal error: Received an RPC response with ID null.');
|
|
797
782
|
// Look up which request promise we should resolve this.
|
|
798
783
|
const requestResolver = this.requestResolvers[message.id];
|
|
799
784
|
// If we do not have a request resolver for this response message..
|
|
@@ -827,12 +812,12 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
827
812
|
// Extract request resolver for readability
|
|
828
813
|
const requestResolver = this.requestResolvers[resolverId];
|
|
829
814
|
// Resolve the active request with an error indicating that the connection was lost.
|
|
830
|
-
requestResolver(new Error(
|
|
815
|
+
requestResolver(new Error('Connection lost'));
|
|
831
816
|
// Remove the promise from the request list.
|
|
832
817
|
delete this.requestResolvers[resolverId];
|
|
833
818
|
}
|
|
834
819
|
// Synchronize with the underlying connection status.
|
|
835
|
-
this.handleConnectionStatusChanges(
|
|
820
|
+
this.handleConnectionStatusChanges('disconnected');
|
|
836
821
|
}
|
|
837
822
|
/**
|
|
838
823
|
* Stores the server provider software version field on successful version negotiation.
|
|
@@ -860,7 +845,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
860
845
|
* @ignore
|
|
861
846
|
*/ async updateChainHeightFromHeadersNotifications(message) {
|
|
862
847
|
// If the message is a notification for a new chain height..
|
|
863
|
-
if (message.method ===
|
|
848
|
+
if (message.method === 'blockchain.headers.subscribe') // ..also store the updated chain height locally.
|
|
864
849
|
this.chainHeight = message.params[0].height;
|
|
865
850
|
}
|
|
866
851
|
/**
|
|
@@ -871,7 +856,7 @@ const $d801b1f9b7fc3074$export$5ba3a4134d0d751d = {
|
|
|
871
856
|
*/ async storeGenesisHashFromFeaturesResponse(message) {
|
|
872
857
|
try {
|
|
873
858
|
// If the message is a response to a features request..
|
|
874
|
-
if (typeof message.result.genesis_hash !==
|
|
859
|
+
if (typeof message.result.genesis_hash !== 'undefined') // ..store the genesis hash locally.
|
|
875
860
|
this.genesisHash = message.result.genesis_hash;
|
|
876
861
|
} catch (error) {
|
|
877
862
|
// Do nothing.
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AGOO,MAAM;IAEZ;;;;;;;;EAQC,GACD,OAAO,mBAAmB,MAAc,EAAE,UAA0B,EAAE,SAA0B,EAChG;QACC,uCAAuC;QACvC,0DAA0D;QAC1D,gHAAgH;QAChH,0EAA0E;QAC1E,OAAO,KAAK,SAAS,CAAC;YAAE,QAAQ;YAAQ,QAAQ;YAAY,IAAI;QAAU;IAC3E;IAEA;;;;EAIC,GACD,WAAW,gBACX;QACC,OAAO;IACR;IAEA;;;;EAIC,GACD,WAAW,qBACX;QACC,OAAO;IACR;AACD;;;;;;;ACgOO,MAAM,4CAAoB,SAAS,MAAW;IAEpD,OAAO,WAAW;AACnB;AAKO,MAAM,4CAAsB,SAAS,MAAW;IAEtD,OAAO,cAAc,UAAU,cAAc;AAC9C;;;ACzRA,8CAA8C;AA0DvC,MAAM,2CAAqB,SAAS,OAAgB;IAE1D,OAAO,QAAQ,WAAW,WAAW;AACtC;AAEO,MAAM,4CAAiB,SAAS,OAAgB;IAEtD,OAAO,QAAQ,WAAW,YAAY;AACvC;AAEO,MAAM,4CAAoB,SAAS,OAAgB;IAEzD,OAAO,CAAE,CA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,EAC3C;QACC,kDAAkD;QAClD,IAAG,iBAAiB,KAAK,EAExB,cAAc;QACd;QAGD,8BAA8B;QAC9B,IAAI,CAAC,QAAQ,GAAG,iBAAiB,QAAQ;IAC1C;IAEA;;;;EAIC,GACD,MAAM,8BACN;QACC,uDAAuD;QACvD,IAAI,CAAC,qBAAqB,GAAG,KAAK,GAAG;IACtC;IAEA;;;;;EAKC,GACD,MAAM,0CAA0C,OAAO,EACvD;QACC,4DAA4D;QAC5D,IAAG,QAAQ,MAAM,KAAK,gCAErB,iDAAiD;QACjD,IAAI,CAAC,WAAW,GAAG,QAAQ,MAAM,CAAC,EAAE,CAAC,MAAM;IAE7C;IAEA;;;;;EAKC,GACD,MAAM,qCAAqC,OAAO,EAClD;QACC,IACA;YACC,uDAAuD;YACvD,IAAG,OAAO,QAAQ,MAAM,CAAC,YAAY,KAAK,aAEzC,oCAAoC;YACpC,IAAI,CAAC,WAAW,GAAG,QAAQ,MAAM,CAAC,YAAY;QAEhD,EACA,OAAM,OACN;QACC,cAAc;QACf;IACD;IAEA;;EAEC,GACD,MAAM,8BAA8B,SAAS,EAC7C;QACC,qBAAqB;QACrB,IAAI,CAAC,IAAI,CAAC;IACX;AAUD;IAEA,qBAAqB;AACrB,2CAAe","sources":["source/index.ts","source/electrum-client.ts","source/electrum-connection.ts","source/electrum-protocol.ts","source/interfaces.ts","source/rpc-interfaces.ts","source/enums.ts","source/constants.ts"],"sourcesContent":["export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './enums';\n","import debug from '@electrum-cash/debug-logs';\nimport { ElectrumConnection } from './electrum-connection';\nimport { ElectrumProtocol } from './electrum-protocol';\nimport { defaultNetworkOptions } from './constants';\nimport { EventEmitter } from 'eventemitter3';\nimport { ConnectionStatus } from './enums';\nimport { RPCParameter, isRPCNotification, isRPCErrorResponse, RPCNotification, RPCResponse } from './rpc-interfaces';\nimport { Mutex } from 'async-mutex';\n\nimport type { ElectrumNetworkOptions, ElectrumClientEvents, ElectrumSocket, ResolveFunction, RequestResolver, RequestResponse } from './interfaces';\n\n/**\n * High-level Electrum client that lets applications send requests and subscribe to notification events from a server.\n */\nclass ElectrumClient<ElectrumEvents extends ElectrumClientEvents> extends EventEmitter<ElectrumClientEvents | ElectrumEvents> implements ElectrumClientEvents\n{\n\t/**\n\t * The name and version of the server software indexing the blockchain.\n\t */\n\tpublic software: string;\n\n\t/**\n\t * The genesis hash of the blockchain indexed by the server.\n\t * @remarks This is only available after a 'server.features' call.\n\t */\n\tpublic genesisHash: string;\n\n\t/**\n\t * The chain height of the blockchain indexed by the server.\n\t * @remarks This is only available after a 'blockchain.headers.subscribe' call.\n\t */\n\tpublic chainHeight: number;\n\n\t/**\n\t * Timestamp of when we last received data from the server indexing the blockchain.\n\t */\n\tpublic lastReceivedTimestamp: number;\n\n\t/**\n\t * Number corresponding to the underlying connection status.\n\t */\n\tpublic get status(): ConnectionStatus\n\t{\n\t\treturn this.connection.status;\n\t}\n\n\t// Declare instance variables\n\tprivate connection: ElectrumConnection;\n\n\t// Initialize an empty list of subscription metadata.\n\tprivate subscriptionMethods: Record<string, Set<string>> = {};\n\n\t// Start counting the request IDs from 0\n\tprivate requestId = 0;\n\n\t// Initialize an empty dictionary for keeping track of request resolvers\n\tprivate requestResolvers: { [index: number]: RequestResolver } = {};\n\n\t// Mutex lock used to prevent simultaneous connect() and disconnect() calls.\n\tprivate connectionLock = new Mutex();\n\n\t/**\n\t * Initializes an Electrum client.\n\t *\n\t * @param application - your application name, used to identify to the electrum host.\n\t * @param version - protocol version to use with the host.\n\t * @param socketOrHostname - pre-configured electrum socket or fully qualified domain name or IP number of the host\n\t * @param options - ...\n\t *\n\t * @throws {Error} if `version` is not a valid version string.\n\t */\n\tconstructor(\n\t\tpublic application: string,\n\t\tpublic version: string,\n\t\tpublic socketOrHostname: ElectrumSocket | string,\n\t\tpublic options: ElectrumNetworkOptions = {},\n\t)\n\t{\n\t\t// Initialize the event emitter.\n\t\tsuper();\n\n\t\t// Update default options with the provided values.\n\t\tconst networkOptions: ElectrumNetworkOptions = { ...defaultNetworkOptions, ...options };\n\n\t\t// Set up a connection to an electrum server.\n\t\tthis.connection = new ElectrumConnection(application, version, socketOrHostname, networkOptions);\n\t}\n\n\t// Expose hostIdentifier from the connection.\n\tget hostIdentifier(): string\n\t{\n\t\treturn this.connection.hostIdentifier;\n\t}\n\n\t// Expose port from the connection.\n\tget encrypted(): boolean\n\t{\n\t\treturn this.connection.encrypted;\n\t}\n\n\t/**\n\t * Connects to the remote server.\n\t *\n\t * @throws {Error} if the socket connection fails.\n\t * @returns a promise resolving when the connection is established.\n\t */\n\tasync connect(): Promise<void>\n\t{\n\t\t// Create a lock so that multiple connects/disconnects cannot race each other.\n\t\tconst unlock = await this.connectionLock.acquire();\n\n\t\ttry\n\t\t{\n\t\t\t// If we are already connected, do not attempt to connect again.\n\t\t\tif(this.connection.status === ConnectionStatus.CONNECTED)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Listen for parsed statements.\n\t\t\tthis.connection.on('response', this.response.bind(this));\n\n\t\t\t// Hook up handles for the connected and disconnected events.\n\t\t\tthis.connection.on('connected', this.resubscribeOnConnect.bind(this));\n\t\t\tthis.connection.on('disconnected', this.onConnectionDisconnect.bind(this));\n\n\t\t\t// Relay connecting and reconnecting events.\n\t\t\tthis.connection.on('connecting', this.handleConnectionStatusChanges.bind(this, 'connecting'));\n\t\t\tthis.connection.on('disconnecting', this.handleConnectionStatusChanges.bind(this, 'disconnecting'));\n\t\t\tthis.connection.on('reconnecting', this.handleConnectionStatusChanges.bind(this, 'reconnecting'));\n\n\t\t\t// Hook up client metadata gathering functions.\n\t\t\tthis.connection.on('version', this.storeSoftwareVersion.bind(this));\n\t\t\tthis.connection.on('received', this.updateLastReceivedTimestamp.bind(this));\n\n\t\t\t// Relay error events.\n\t\t\tthis.connection.on('error', this.emit.bind(this, 'error'));\n\n\t\t\t// Connect with the server.\n\t\t\tawait this.connection.connect();\n\t\t}\n\t\t// Always release our lock so that we do not end up in a stuck-state.\n\t\tfinally\n\t\t{\n\t\t\tunlock();\n\t\t}\n\t}\n\n\t/**\n\t * Disconnects from the remote server and removes all event listeners/subscriptions and open requests.\n\t *\n\t * @param force - disconnect even if the connection has not been fully established yet.\n\t * @param retainSubscriptions - retain subscription data so they will be restored on reconnection.\n\t *\n\t * @returns true if successfully disconnected, or false if there was no connection.\n\t */\n\tasync disconnect(force: boolean = false, retainSubscriptions: boolean = false): Promise<boolean>\n\t{\n\t\tif(!retainSubscriptions)\n\t\t{\n\t\t\t// Cancel all event listeners.\n\t\t\tthis.removeAllListeners();\n\n\t\t\t// Remove all subscription data\n\t\t\tthis.subscriptionMethods = {};\n\t\t}\n\n\t\t// Disconnect from the remote server.\n\t\treturn this.connection.disconnect(force);\n\t}\n\n\t/**\n\t * Calls a method on the remote server with the supplied parameters.\n\t *\n\t * @param method - name of the method to call.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise that resolves with the result of the method or an Error.\n\t */\n\tasync request(method: string, ...parameters: RPCParameter[]): Promise<Error | RequestResponse>\n\t{\n\t\t// If we are not connected to a server..\n\t\tif(this.connection.status !== ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\t// Reject the request with a disconnected error message.\n\t\t\tthrow(new Error(`Unable to send request to a disconnected server '${this.hostIdentifier}'.`));\n\t\t}\n\n\t\t// Increase the request ID by one.\n\t\tthis.requestId += 1;\n\n\t\t// Store a copy of the request id.\n\t\tconst id = this.requestId;\n\n\t\t// Format the arguments as an electrum request object.\n\t\tconst message = ElectrumProtocol.buildRequestObject(method, parameters, id);\n\n\t\t// Define a function to wrap the request in a promise.\n\t\tconst requestResolver = (resolve: ResolveFunction<Error | RequestResponse>): void =>\n\t\t{\n\t\t\t// Add a request resolver for this promise to the list of requests.\n\t\t\tthis.requestResolvers[id] = (error?: Error, data?: RequestResponse) =>\n\t\t\t{\n\t\t\t\t// If the resolution failed..\n\t\t\t\tif(error)\n\t\t\t\t{\n\t\t\t\t\t// Resolve the promise with the error for the application to handle.\n\t\t\t\t\tresolve(error);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t// Resolve the promise with the request results.\n\t\t\t\t\tresolve(data);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Send the request message to the remote server.\n\t\t\tthis.connection.send(message);\n\t\t};\n\n\t\t// Write a log message.\n\t\tdebug.network(`Sending request '${method}' to '${this.hostIdentifier}'`);\n\n\t\t// return a promise to deliver results later.\n\t\treturn new Promise<Error | RequestResponse>(requestResolver);\n\t}\n\n\t/**\n\t * Subscribes to the method and payload at the server.\n\t *\n\t * @remarks the response for the subscription request is issued as a notification event.\n\t *\n\t * @param method - one of the subscribable methods the server supports.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving when the subscription is established.\n\t */\n\tasync subscribe(method: string, ...parameters: RPCParameter[]): Promise<void>\n\t{\n\t\t// Initialize an empty list of subscription payloads, if needed.\n\t\tif(!this.subscriptionMethods[method])\n\t\t{\n\t\t\tthis.subscriptionMethods[method] = new Set<string>();\n\t\t}\n\n\t\t// Store the subscription parameters to track what data we have subscribed to.\n\t\tthis.subscriptionMethods[method].add(JSON.stringify(parameters));\n\n\t\t// Send initial subscription request.\n\t\tconst requestData = await this.request(method, ...parameters);\n\n\t\t// If the request failed, throw it as an error.\n\t\tif(requestData instanceof Error)\n\t\t{\n\t\t\tthrow(requestData);\n\t\t}\n\n\t\t// If the request returned more than one data point..\n\t\tif(Array.isArray(requestData))\n\t\t{\n\t\t\t// .. throw an error, as this breaks our expectation for subscriptions.\n\t\t\tthrow(new Error('Subscription request returned an more than one data point.'));\n\t\t}\n\n\t\t// Construct a notification structure to package the initial result as a notification.\n\t\tconst notification: RPCNotification =\n\t\t{\n\t\t\tjsonrpc: '2.0',\n\t\t\tmethod: method,\n\t\t\tparams: [ ...parameters, requestData ],\n\t\t};\n\n\t\t// Manually emit an event for the initial response.\n\t\tthis.emit('notification', notification);\n\n\t\t// Try to update the chain height.\n\t\tthis.updateChainHeightFromHeadersNotifications(notification);\n\t}\n\n\t/**\n\t * Unsubscribes to the method at the server and removes any callback functions\n\t * when there are no more subscriptions for the method.\n\t *\n\t * @param method - a previously subscribed to method.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if no subscriptions exist for the combination of the provided `method` and `parameters.\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving when the subscription is removed.\n\t */\n\tasync unsubscribe(method: string, ...parameters: RPCParameter[]): Promise<void>\n\t{\n\t\t// Throw an error if the client is disconnected.\n\t\tif(this.connection.status !== ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\tthrow(new Error(`Unable to send unsubscribe request to a disconnected server '${this.hostIdentifier}'.`));\n\t\t}\n\n\t\t// If this method has no subscriptions..\n\t\tif(!this.subscriptionMethods[method])\n\t\t{\n\t\t\t// Reject this promise with an explanation.\n\t\t\tthrow(new Error(`Cannot unsubscribe from '${method}' since the method has no subscriptions.`));\n\t\t}\n\n\t\t// Pack up the parameters as a long string.\n\t\tconst subscriptionParameters = JSON.stringify(parameters);\n\n\t\t// If the method payload could not be located..\n\t\tif(!this.subscriptionMethods[method].has(subscriptionParameters))\n\t\t{\n\t\t\t// Reject this promise with an explanation.\n\t\t\tthrow(new Error(`Cannot unsubscribe from '${method}' since it has no subscription with the given parameters.`));\n\t\t}\n\n\t\t// Remove this specific subscription payload from internal tracking.\n\t\tthis.subscriptionMethods[method].delete(subscriptionParameters);\n\n\t\t// Send unsubscription request to the server\n\t\t// NOTE: As a convenience we allow users to define the method as the subscribe or unsubscribe version.\n\t\tawait this.request(method.replace('.subscribe', '.unsubscribe'), ...parameters);\n\n\t\t// Write a log message.\n\t\tdebug.client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);\n\t}\n\n\t/**\n\t * Restores existing subscriptions without updating status or triggering manual callbacks.\n\t *\n\t * @throws {Error} if subscription data cannot be found for all stored event names.\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving to true when the subscriptions are restored.\n\t *\n\t * @ignore\n\t */\n\tprivate async resubscribeOnConnect(): Promise<void>\n\t{\n\t\t// Write a log message.\n\t\tdebug.client(`Connected to '${this.hostIdentifier}'.`);\n\n\t\t// Synchronize with the underlying connection status.\n\t\tthis.handleConnectionStatusChanges('connected');\n\n\t\t// Initialize an empty list of resubscription promises.\n\t\tconst resubscriptionPromises = [];\n\n\t\t// For each method we have a subscription for..\n\t\tfor(const method in this.subscriptionMethods)\n\t\t{\n\t\t\t// .. and for each parameter we have previously been subscribed to..\n\t\t\tfor(const parameterJSON of this.subscriptionMethods[method].values())\n\t\t\t{\n\t\t\t\t// restore the parameters from JSON.\n\t\t\t\tconst parameters = JSON.parse(parameterJSON);\n\n\t\t\t\t// Send a subscription request.\n\t\t\t\tresubscriptionPromises.push(this.subscribe(method, ...parameters));\n\t\t\t}\n\n\t\t\t// Wait for all re-subscriptions to complete.\n\t\t\tawait Promise.all(resubscriptionPromises);\n\t\t}\n\n\t\t// Write a log message if there was any subscriptions to restore.\n\t\tif(resubscriptionPromises.length > 0)\n\t\t{\n\t\t\tdebug.client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.hostIdentifier}'`);\n\t\t}\n\t}\n\n\t/**\n\t * Parser messages from the remote server to resolve request promises and emit subscription events.\n\t *\n\t * @param message - the response message\n\t *\n\t * @throws {Error} if the message ID does not match an existing request.\n\t * @ignore\n\t */\n\tresponse(message: RPCResponse): void\n\t{\n\t\t// If the received message is a notification, we forward it to all event listeners\n\t\tif(isRPCNotification(message))\n\t\t{\n\t\t\t// Write a log message.\n\t\t\tdebug.client(`Received notification for '${message.method}' from '${this.hostIdentifier}'`);\n\n\t\t\t// Forward the message content to all event listeners.\n\t\t\tthis.emit('notification', message);\n\n\t\t\t// Try to update the chain height.\n\t\t\tthis.updateChainHeightFromHeadersNotifications(message);\n\n\t\t\t// Return since it does not have an associated request resolver\n\t\t\treturn;\n\t\t}\n\n\t\t// If the response ID is null we cannot use it to index our request resolvers\n\t\tif(message.id === null)\n\t\t{\n\t\t\t// Throw an internal error, this should not happen.\n\t\t\tthrow(new Error('Internal error: Received an RPC response with ID null.'));\n\t\t}\n\n\t\t// Look up which request promise we should resolve this.\n\t\tconst requestResolver = this.requestResolvers[message.id];\n\n\t\t// If we do not have a request resolver for this response message..\n\t\tif(!requestResolver)\n\t\t{\n\t\t\t// Log that a message was ignored since the request has already been rejected.\n\t\t\tdebug.warning(`Ignoring response #${message.id} as the request has already been rejected.`);\n\n\t\t\t// Return as this has now been fully handled.\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove the promise from the request list.\n\t\tdelete this.requestResolvers[message.id];\n\n\t\t// If the message contains an error..\n\t\tif(isRPCErrorResponse(message))\n\t\t{\n\t\t\t// Forward the message error to the request resolver and omit the `result` parameter.\n\t\t\trequestResolver(new Error(message.error.message));\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Forward the message content to the request resolver and omit the `error` parameter\n\t\t\t// (by setting it to undefined).\n\t\t\trequestResolver(undefined, message.result);\n\n\t\t\t// Attempt to extract genesis hash from feature requests.\n\t\t\tthis.storeGenesisHashFromFeaturesResponse(message);\n\t\t}\n\t}\n\n\t/**\n\t * Callback function that is called when connection to the Electrum server is lost.\n\t * Aborts all active requests with an error message indicating that connection was lost.\n\t *\n\t * @ignore\n\t */\n\tasync onConnectionDisconnect(): Promise<void>\n\t{\n\t\t// Loop over active requests\n\t\tfor(const resolverId in this.requestResolvers)\n\t\t{\n\t\t\t// Extract request resolver for readability\n\t\t\tconst requestResolver = this.requestResolvers[resolverId];\n\n\t\t\t// Resolve the active request with an error indicating that the connection was lost.\n\t\t\trequestResolver(new Error('Connection lost'));\n\n\t\t\t// Remove the promise from the request list.\n\t\t\tdelete this.requestResolvers[resolverId];\n\t\t}\n\n\t\t// Synchronize with the underlying connection status.\n\t\tthis.handleConnectionStatusChanges('disconnected');\n\t}\n\n\t/**\n\t * Stores the server provider software version field on successful version negotiation.\n\t *\n\t * @ignore\n\t */\n\tasync storeSoftwareVersion(versionStatement): Promise<void>\n\t{\n\t\t// TODO: handle failed version negotiation better.\n\t\tif(versionStatement.error)\n\t\t{\n\t\t\t// Do nothing.\n\t\t\treturn;\n\t\t}\n\n\t\t// Store the software version.\n\t\tthis.software = versionStatement.software;\n\t}\n\n\t/**\n\t * Updates the last received timestamp.\n\t *\n\t * @ignore\n\t */\n\tasync updateLastReceivedTimestamp(): Promise<void>\n\t{\n\t\t// Update the timestamp for when we last received data.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\t}\n\n\t/**\n\t * Checks if the provided message is a response to a headers subscription,\n\t * and if so updates the locally stored chain height value for this client.\n\t *\n\t * @ignore\n\t */\n\tasync updateChainHeightFromHeadersNotifications(message): Promise<void>\n\t{\n\t\t// If the message is a notification for a new chain height..\n\t\tif(message.method === 'blockchain.headers.subscribe')\n\t\t{\n\t\t\t// ..also store the updated chain height locally.\n\t\t\tthis.chainHeight = message.params[0].height;\n\t\t}\n\t}\n\n\t/**\n\t * Checks if the provided message is a response to a server.features request,\n\t * and if so stores the genesis hash for this client locally.\n\t *\n\t * @ignore\n\t */\n\tasync storeGenesisHashFromFeaturesResponse(message): Promise<void>\n\t{\n\t\ttry\n\t\t{\n\t\t\t// If the message is a response to a features request..\n\t\t\tif(typeof message.result.genesis_hash !== 'undefined')\n\t\t\t{\n\t\t\t\t// ..store the genesis hash locally.\n\t\t\t\tthis.genesisHash = message.result.genesis_hash;\n\t\t\t}\n\t\t}\n\t\tcatch(error)\n\t\t{\n\t\t\t// Do nothing.\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to synchronize state and events with the underlying connection.\n\t */\n\tasync handleConnectionStatusChanges(eventName): Promise<void>\n\t{\n\t\t// Re-emit the event.\n\t\tthis.emit(eventName);\n\t}\n\n\t// Add magic glue that makes typedoc happy so that we can have the events listed on the class.\n\tpublic readonly connecting: [];\n\tpublic readonly connected: [];\n\tpublic readonly disconnecting: [];\n\tpublic readonly disconnected: [];\n\tpublic readonly reconnecting: [];\n\tpublic readonly notification: [ RPCNotification ];\n\tpublic readonly error: [ Error ];\n}\n\n// Export the client.\nexport default ElectrumClient;\n","import debug from '@electrum-cash/debug-logs';\nimport { ElectrumWebSocket } from '@electrum-cash/web-socket';\nimport { ElectrumProtocol } from './electrum-protocol';\nimport { ElectrumNetworkOptions, ElectrumConnectionEvents, ElectrumSocket, ResolveFunction, RejectFunction, VersionNegotiationResponse, isVersionRejected } from './interfaces';\nimport { isRPCNotification, isRPCErrorResponse, RPCResponse, RPCErrorResponse } from './rpc-interfaces';\nimport { EventEmitter } from 'eventemitter3';\nimport { ConnectionStatus } from './enums';\nimport { parse, parseNumberAndBigInt } from 'lossless-json';\n\n/**\n * Wrapper around TLS/WSS sockets that gracefully separates a network stream into Electrum protocol messages.\n */\nexport class ElectrumConnection extends EventEmitter<ElectrumConnectionEvents>\n{\n\t// Initialize the connected flag to false to indicate that there is no connection\n\tpublic status: ConnectionStatus = ConnectionStatus.DISCONNECTED;\n\n\t// Declare empty timestamps\n\tprivate lastReceivedTimestamp: number;\n\n\t// Declare an empty socket.\n\tprivate socket: ElectrumSocket;\n\n\t// Declare timers for keep-alive pings and reconnection\n\tprivate keepAliveTimer?: number;\n\tprivate reconnectTimer?: number;\n\n\t// Initialize an empty array of connection verification timers.\n\tprivate verifications: Array<number> = [];\n\n\t// Initialize messageBuffer to an empty string\n\tprivate messageBuffer = '';\n\n\t/**\n\t * Sets up network configuration for an Electrum client connection.\n\t *\n\t * @param application - your application name, used to identify to the electrum host.\n\t * @param version - protocol version to use with the host.\n\t * @param socketOrHostname - pre-configured electrum socket or fully qualified domain name or IP number of the host\n\t * @param options - ...\n\t *\n\t * @throws {Error} if `version` is not a valid version string.\n\t */\n\tconstructor(\n\t\tprivate application: string,\n\t\tprivate version: string,\n\t\tprivate socketOrHostname: ElectrumSocket | string,\n\t\tprivate options: ElectrumNetworkOptions,\n\t)\n\t{\n\t\t// Initialize the event emitter.\n\t\tsuper();\n\n\t\t// Check if the provided version is a valid version number.\n\t\tif(!ElectrumProtocol.versionRegexp.test(version))\n\t\t{\n\t\t\t// Throw an error since the version number was not valid.\n\t\t\tthrow(new Error(`Provided version string (${version}) is not a valid protocol version number.`));\n\t\t}\n\n\t\t// If a hostname was provided..\n\t\tif(typeof socketOrHostname === 'string')\n\t\t{\n\t\t\t// Use a web socket with default parameters.\n\t\t\tthis.socket = new ElectrumWebSocket(socketOrHostname);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Use the provided socket.\n\t\t\tthis.socket = socketOrHostname;\n\t\t}\n\n\t\t// Set up handlers for connection and disconnection.\n\t\tthis.socket.on('connected', this.onSocketConnect.bind(this));\n\t\tthis.socket.on('disconnected', this.onSocketDisconnect.bind(this));\n\n\t\t// Set up handler for incoming data.\n\t\tthis.socket.on('data', this.parseMessageChunk.bind(this));\n\n\t\t// Handle visibility changes when run in a browser environment (if not explicitly disabled).\n\t\tif(typeof document !== 'undefined' && !this.options.disableBrowserVisibilityHandling)\n\t\t{\n\t\t\tdocument.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));\n\t\t}\n\n\t\t// Handle network connection changes when run in a browser environment (if not explicitly disabled).\n\t\tif(typeof window !== 'undefined' && !this.options.disableBrowserConnectivityHandling)\n\t\t{\n\t\t\twindow.addEventListener('online', this.handleNetworkChange.bind(this));\n\t\t\twindow.addEventListener('offline', this.handleNetworkChange.bind(this));\n\t\t}\n\t}\n\n\t// Expose hostIdentifier from the socket.\n\tget hostIdentifier(): string\n\t{\n\t\treturn this.socket.hostIdentifier;\n\t}\n\n\t// Expose port from the socket.\n\tget encrypted(): boolean\n\t{\n\t\treturn this.socket.encrypted;\n\t}\n\n\t/**\n\t * Assembles incoming data into statements and hands them off to the message parser.\n\t *\n\t * @param data - data to append to the current message buffer, as a string.\n\t *\n\t * @throws {SyntaxError} if the passed statement parts are not valid JSON.\n\t */\n\tparseMessageChunk(data: string): void\n\t{\n\t\t// Update the timestamp for when we last received data.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\n\t\t// Emit a notification indicating that the connection has received data.\n\t\tthis.emit('received');\n\n\t\t// Clear and remove all verification timers.\n\t\tthis.verifications.forEach((timer) => clearTimeout(timer));\n\t\tthis.verifications.length = 0;\n\n\t\t// Add the message to the current message buffer.\n\t\tthis.messageBuffer += data;\n\n\t\t// Check if the new message buffer contains the statement delimiter.\n\t\twhile(this.messageBuffer.includes(ElectrumProtocol.statementDelimiter))\n\t\t{\n\t\t\t// Split message buffer into statements.\n\t\t\tconst statementParts = this.messageBuffer.split(ElectrumProtocol.statementDelimiter);\n\n\t\t\t// For as long as we still have statements to parse..\n\t\t\twhile(statementParts.length > 1)\n\t\t\t{\n\t\t\t\t// Move the first statement to its own variable.\n\t\t\t\tconst currentStatementList = String(statementParts.shift());\n\n\t\t\t\t// Parse the statement into an object or list of objects.\n\t\t\t\tlet statementList = parse(currentStatementList, null, this.options.useBigInt ? parseNumberAndBigInt : parseFloat) as RPCResponse | RPCResponse[];\n\n\t\t\t\t// Wrap the statement in an array if it is not already a batched statement list.\n\t\t\t\tif(!Array.isArray(statementList))\n\t\t\t\t{\n\t\t\t\t\tstatementList = [ statementList ];\n\t\t\t\t}\n\n\t\t\t\t// For as long as there is statements in the result set..\n\t\t\t\twhile(statementList.length > 0)\n\t\t\t\t{\n\t\t\t\t\t// Move the first statement from the batch to its own variable.\n\t\t\t\t\tconst currentStatement = statementList.shift();\n\n\t\t\t\t\t// If the current statement is a subscription notification..\n\t\t\t\t\tif(isRPCNotification(currentStatement))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Emit the notification for handling higher up in the stack.\n\t\t\t\t\t\tthis.emit('response', currentStatement);\n\n\t\t\t\t\t\t// Consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the current statement is a version negotiation response..\n\t\t\t\t\tif(currentStatement.id === 'versionNegotiation')\n\t\t\t\t\t{\n\t\t\t\t\t\tif(isRPCErrorResponse(currentStatement))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// Then emit a failed version negotiation response signal.\n\t\t\t\t\t\t\tthis.emit('version', { error: currentStatement.error });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// Extract the software and protocol version reported.\n\t\t\t\t\t\t\tconst [ software, protocol ] = currentStatement.result;\n\n\t\t\t\t\t\t\t// Emit a successful version negotiation response signal.\n\t\t\t\t\t\t\tthis.emit('version', { software, protocol });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the current statement is a keep-alive response..\n\t\t\t\t\tif(currentStatement.id === 'keepAlive')\n\t\t\t\t\t{\n\t\t\t\t\t\t// Do nothing and consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Emit the statements for handling higher up in the stack.\n\t\t\t\t\tthis.emit('response', currentStatement);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Store the remaining statement as the current message buffer.\n\t\t\tthis.messageBuffer = statementParts.shift() || '';\n\t\t}\n\t}\n\n\t/**\n\t * Sends a keep-alive message to the host.\n\t *\n\t * @returns true if the ping message was fully flushed to the socket, false if\n\t * part of the message is queued in the user memory\n\t */\n\tping(): boolean\n\t{\n\t\t// Write a log message.\n\t\tdebug.ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);\n\n\t\t// Craft a keep-alive message.\n\t\tconst message = ElectrumProtocol.buildRequestObject('server.ping', [], 'keepAlive');\n\n\t\t// Send the keep-alive message.\n\t\tconst status = this.send(message);\n\n\t\t// Return the ping status.\n\t\treturn status;\n\t}\n\n\t/**\n\t * Initiates the network connection negotiates a protocol version. Also emits the 'connect' signal if successful.\n\t *\n\t * @throws {Error} if the socket connection fails.\n\t * @returns a promise resolving when the connection is established\n\t */\n\tasync connect(): Promise<void>\n\t{\n\t\t// If we are already connected return true.\n\t\tif(this.status === ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Indicate that the connection is connecting\n\t\tthis.status = ConnectionStatus.CONNECTING;\n\n\t\t// Emit a connect event now that the connection is being set up.\n\t\tthis.emit('connecting');\n\n\t\t// Define a function to wrap connection as a promise.\n\t\tconst connectionResolver = (resolve: ResolveFunction<void>, reject: RejectFunction): void =>\n\t\t{\n\t\t\tconst rejector = (error: Error): void =>\n\t\t\t{\n\t\t\t\t// Set the status back to disconnected\n\t\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t\t// Emit a connect event indicating that we failed to connect.\n\t\t\t\tthis.emit('disconnected');\n\n\t\t\t\t// Reject with the error as reason\n\t\t\t\treject(error);\n\t\t\t};\n\n\t\t\t// Replace previous error handlers to reject the promise on failure.\n\t\t\tthis.socket.removeAllListeners('error');\n\t\t\tthis.socket.once('error', rejector);\n\n\t\t\t// Define a function to wrap version negotiation as a callback.\n\t\t\tconst versionNegotiator = (): void =>\n\t\t\t{\n\t\t\t\t// Write a log message to show that we have started version negotiation.\n\t\t\t\tdebug.network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);\n\n\t\t\t\t// remove the one-time error handler since no error was detected.\n\t\t\t\tthis.socket.removeListener('error', rejector);\n\n\t\t\t\t// Build a version negotiation message.\n\t\t\t\tconst versionMessage = ElectrumProtocol.buildRequestObject('server.version', [ this.application, this.version ], 'versionNegotiation');\n\n\t\t\t\t// Define a function to wrap version validation as a function.\n\t\t\t\tconst versionValidator = (version: VersionNegotiationResponse): void =>\n\t\t\t\t{\n\t\t\t\t\t// Check if version negotiation failed.\n\t\t\t\t\tif(isVersionRejected(version))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Disconnect from the host.\n\t\t\t\t\t\tthis.disconnect(true);\n\n\t\t\t\t\t\t// Declare an error message.\n\t\t\t\t\t\tconst errorMessage = 'unsupported protocol version.';\n\n\t\t\t\t\t\t// Log the error.\n\t\t\t\t\t\tdebug.errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);\n\n\t\t\t\t\t\t// Reject the connection with false since version negotiation failed.\n\t\t\t\t\t\treject(errorMessage);\n\t\t\t\t\t}\n\t\t\t\t\t// Check if the host supports our requested protocol version.\n\t\t\t\t\t// NOTE: the server responds with version numbers that truncate 0's, so 1.5.0 turns into 1.5.\n\t\t\t\t\telse if((version.protocol !== this.version) && (`${version.protocol}.0` !== this.version) && (`${version.protocol}.0.0` !== this.version))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Disconnect from the host.\n\t\t\t\t\t\tthis.disconnect(true);\n\n\t\t\t\t\t\t// Declare an error message.\n\t\t\t\t\t\tconst errorMessage = `incompatible protocol version negotiated (${version.protocol} !== ${this.version}).`;\n\n\t\t\t\t\t\t// Log the error.\n\t\t\t\t\t\tdebug.errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);\n\n\t\t\t\t\t\t// Reject the connection with false since version negotiation failed.\n\t\t\t\t\t\treject(errorMessage);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t// Write a log message.\n\t\t\t\t\t\tdebug.network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);\n\n\t\t\t\t\t\t// Set connection status to connected\n\t\t\t\t\t\tthis.status = ConnectionStatus.CONNECTED;\n\n\t\t\t\t\t\t// Emit a connect event now that the connection is usable.\n\t\t\t\t\t\tthis.emit('connected');\n\n\t\t\t\t\t\t// Resolve the connection promise since we successfully connected and negotiated protocol version.\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Listen for version negotiation once.\n\t\t\t\tthis.once('version', versionValidator);\n\n\t\t\t\t// Send the version negotiation message.\n\t\t\t\tthis.send(versionMessage);\n\t\t\t};\n\n\t\t\t// Prepare the version negotiation.\n\t\t\tthis.socket.once('connected', versionNegotiator);\n\n\t\t\t// Set up handler for network errors.\n\t\t\tthis.socket.on('error', this.onSocketError.bind(this));\n\n\t\t\t// Connect to the server.\n\t\t\tthis.socket.connect();\n\t\t};\n\n\t\t// Wait until connection is established and version negotiation succeeds.\n\t\tawait new Promise<void>(connectionResolver);\n\t}\n\n\t/**\n\t * Restores the network connection.\n\t */\n\tasync reconnect(): Promise<void>\n\t{\n\t\t// If a reconnect timer is set, remove it\n\t\tawait this.clearReconnectTimer();\n\n\t\t// Write a log message.\n\t\tdebug.network(`Trying to reconnect to '${this.hostIdentifier}'..`);\n\n\t\t// Set the status to reconnecting for more accurate log messages.\n\t\tthis.status = ConnectionStatus.RECONNECTING;\n\n\t\t// Emit a connect event now that the connection is usable.\n\t\tthis.emit('reconnecting');\n\n\t\t// Disconnect the underlying socket.\n\t\tthis.socket.disconnect();\n\n\t\ttry\n\t\t{\n\t\t\t// Try to connect again.\n\t\t\tawait this.connect();\n\t\t}\n\t\tcatch(error)\n\t\t{\n\t\t\t// Do nothing as the error should be handled via the disconnect and error signals.\n\t\t}\n\t}\n\n\t/**\n\t * Removes the current reconnect timer.\n\t */\n\tclearReconnectTimer(): void\n\t{\n\t\t// If a reconnect timer is set, remove it\n\t\tif(this.reconnectTimer)\n\t\t{\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.reconnectTimer = undefined;\n\t}\n\n\t/**\n\t * Removes the current keep-alive timer.\n\t */\n\tclearKeepAliveTimer(): void\n\t{\n\t\t// If a keep-alive timer is set, remove it\n\t\tif(this.keepAliveTimer)\n\t\t{\n\t\t\tclearTimeout(this.keepAliveTimer);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.keepAliveTimer = undefined;\n\t}\n\n\t/**\n\t * Initializes the keep alive timer loop.\n\t */\n\tsetupKeepAliveTimer(): void\n\t{\n\t\t// If the keep-alive timer loop is not currently set up..\n\t\tif(!this.keepAliveTimer)\n\t\t{\n\t\t\t// Set a new keep-alive timer.\n\t\t\tthis.keepAliveTimer = setTimeout(this.ping.bind(this), this.options.sendKeepAliveIntervalInMilliSeconds) as unknown as number;\n\t\t}\n\t}\n\n\t/**\n\t * Tears down the current connection and removes all event listeners on disconnect.\n\t *\n\t * @param force - disconnect even if the connection has not been fully established yet.\n\t * @param intentional - update connection state if disconnect is intentional.\n\t *\n\t * @returns true if successfully disconnected, or false if there was no connection.\n\t */\n\tasync disconnect(force: boolean = false, intentional: boolean = true): Promise<boolean>\n\t{\n\t\t// Return early when there is nothing to disconnect from\n\t\tif(this.status === ConnectionStatus.DISCONNECTED && !force)\n\t\t{\n\t\t\t// Return false to indicate that there was nothing to disconnect from.\n\t\t\treturn false;\n\t\t}\n\n\t\t// Update connection state if the disconnection is intentional.\n\t\t// NOTE: The state is meant to represent what the client is requesting, but\n\t\t// is used internally to handle visibility changes in browsers to ensure functional reconnection.\n\t\tif(intentional)\n\t\t{\n\t\t\t// Set connection status to null to indicate tear-down is currently happening.\n\t\t\tthis.status = ConnectionStatus.DISCONNECTING;\n\t\t}\n\n\t\t// Emit a connect event to indicate that we are disconnecting.\n\t\tthis.emit('disconnecting');\n\n\t\t// If a keep-alive timer is set, remove it.\n\t\tawait this.clearKeepAliveTimer();\n\n\t\t// If a reconnect timer is set, remove it\n\t\tawait this.clearReconnectTimer();\n\n\t\tconst disconnectResolver = (resolve: ResolveFunction<boolean>): void =>\n\t\t{\n\t\t\t// Resolve to true after the connection emits a disconnect\n\t\t\tthis.once('disconnected', () => resolve(true));\n\n\t\t\t// Close the connection on the socket level.\n\t\t\tthis.socket.disconnect();\n\t\t};\n\n\t\t// Return true to indicate that we disconnected.\n\t\treturn new Promise<boolean>(disconnectResolver);\n\t}\n\n\t/**\n\t * Updates the connection state based on browser reported connectivity.\n\t *\n\t * Most modern browsers are able to provide information on the connection state\n\t * which allows for significantly faster response times to network changes compared\n\t * to waiting for network requests to fail.\n\t *\n\t * When available, we make use of this to fail early to provide a better user experience.\n\t */\n\tasync handleNetworkChange(): Promise<void>\n\t{\n\t\t// Do nothing if we do not have the navigator available.\n\t\tif(typeof window.navigator === 'undefined')\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Attempt to reconnect to the network now that we may be online again.\n\t\tif(window.navigator.onLine === true)\n\t\t{\n\t\t\tthis.reconnect();\n\t\t}\n\n\t\t// Disconnected from the network so that cleanup can happen while we're offline.\n\t\tif(window.navigator.onLine !== true)\n\t\t{\n\t\t\tconst forceDisconnect = true;\n\t\t\tconst isIntentional = true;\n\n\t\t\tthis.disconnect(forceDisconnect, isIntentional);\n\t\t}\n\t}\n\n\t/**\n\t * Updates connection state based on application visibility.\n\t *\n\t * Some browsers will disconnect network connections when the browser is out of focus,\n\t * which would normally cause our reconnect-on-timeout routines to trigger, but that\n\t * results in a poor user experience since the events are not handled consistently\n\t * and sometimes it can take some time after restoring focus to the browser.\n\t *\n\t * By manually disconnecting when this happens we prevent the default reconnection routines\n\t * and make the behavior consistent across browsers.\n\t */\n\tasync handleVisibilityChange(): Promise<void>\n\t{\n\t\t// Disconnect when application is removed from focus.\n\t\tif(document.visibilityState === 'hidden')\n\t\t{\n\t\t\tconst forceDisconnect = true;\n\t\t\tconst isIntentional = true;\n\n\t\t\tthis.disconnect(forceDisconnect, isIntentional);\n\t\t}\n\n\t\t// Reconnect when application is returned to focus.\n\t\tif(document.visibilityState === 'visible')\n\t\t{\n\t\t\tthis.reconnect();\n\t\t}\n\t}\n\n\t/**\n\t * Sends an arbitrary message to the server.\n\t *\n\t * @param message - json encoded request object to send to the server, as a string.\n\t *\n\t * @returns true if the message was fully flushed to the socket, false if part of the message\n\t * is queued in the user memory\n\t */\n\tsend(message: string): boolean\n\t{\n\t\t// Remove the current keep-alive timer if it exists.\n\t\tthis.clearKeepAliveTimer();\n\n\t\t// Get the current timestamp in milliseconds.\n\t\tconst currentTime = Date.now();\n\n\t\t// Follow up and verify that the message got sent..\n\t\tconst verificationTimer = setTimeout(this.verifySend.bind(this, currentTime), this.socket.timeout) as unknown as number;\n\n\t\t// Store the verification timer locally so that it can be cleared when data has been received.\n\t\tthis.verifications.push(verificationTimer);\n\n\t\t// Set a new keep-alive timer.\n\t\tthis.setupKeepAliveTimer();\n\n\t\t// Write the message to the network socket.\n\t\treturn this.socket.write(message + ElectrumProtocol.statementDelimiter);\n\t}\n\n\t// --- Event managers. --- //\n\n\t/**\n\t * Marks the connection as timed out and schedules reconnection if we have not\n\t * received data within the expected time frame.\n\t */\n\tverifySend(sentTimestamp: number): void\n\t{\n\t\t// If we haven't received any data since we last sent data out..\n\t\tif(Number(this.lastReceivedTimestamp) < sentTimestamp)\n\t\t{\n\t\t\t// If this connection is already disconnected, we do not change anything\n\t\t\tif((this.status === ConnectionStatus.DISCONNECTED) || (this.status === ConnectionStatus.DISCONNECTING))\n\t\t\t{\n\t\t\t\t// debug.warning(`Tried to verify already disconnected connection to '${this.hostIdentifier}'`);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Remove the current keep-alive timer if it exists.\n\t\t\tthis.clearKeepAliveTimer();\n\n\t\t\t// Write a notification to the logs.\n\t\t\tdebug.network(`Connection to '${this.hostIdentifier}' timed out.`);\n\n\t\t\t// Close the connection to avoid re-use.\n\t\t\t// NOTE: This initiates reconnection routines if the connection has not\n\t\t\t// been marked as intentionally disconnected.\n\t\t\tthis.socket.disconnect();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the connection status when a connection is confirmed.\n\t */\n\tonSocketConnect(): void\n\t{\n\t\t// If a reconnect timer is set, remove it.\n\t\tthis.clearReconnectTimer();\n\n\t\t// Set up the initial timestamp for when we last received data from the server.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\n\t\t// Set up the initial keep-alive timer.\n\t\tthis.setupKeepAliveTimer();\n\n\t\t// Clear all temporary error listeners.\n\t\tthis.socket.removeAllListeners('error');\n\n\t\t// Set up handler for network errors.\n\t\tthis.socket.on('error', this.onSocketError.bind(this));\n\t}\n\n\t/**\n\t * Updates the connection status when a connection is ended.\n\t */\n\tonSocketDisconnect(): void\n\t{\n\t\t// Remove the current keep-alive timer if it exists.\n\t\tthis.clearKeepAliveTimer();\n\n\t\t// If this is a connection we're trying to tear down..\n\t\tif(this.status === ConnectionStatus.DISCONNECTING)\n\t\t{\n\t\t\t// Mark the connection as disconnected.\n\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t// Send a disconnect signal higher up the stack.\n\t\t\tthis.emit('disconnected');\n\n\t\t\t// If a reconnect timer is set, remove it.\n\t\t\tthis.clearReconnectTimer();\n\n\t\t\t// Remove all event listeners\n\t\t\tthis.removeAllListeners();\n\n\t\t\t// Write a log message.\n\t\t\tdebug.network(`Disconnected from '${this.hostIdentifier}'.`);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// If this is for an established connection..\n\t\t\tif(this.status === ConnectionStatus.CONNECTED)\n\t\t\t{\n\t\t\t\t// Write a notification to the logs.\n\t\t\t\tdebug.errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.options.reconnectAfterMilliSeconds / 1000} seconds.`);\n\t\t\t}\n\t\t\t// If this is a connection that is currently connecting, reconnecting or already disconnected..\n\t\t\telse\n\t\t\t{\n\t\t\t\t// Do nothing\n\n\t\t\t\t// NOTE: This error message is useful during manual debugging of reconnections.\n\t\t\t\t// debug.errors(`Lost connection with reconnecting or already disconnected server '${this.hostIdentifier}'.`);\n\t\t\t}\n\n\t\t\t// Mark the connection as disconnected for now..\n\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t// Send a disconnect signal higher up the stack.\n\t\t\tthis.emit('disconnected');\n\n\t\t\t// If we don't have a pending reconnection timer..\n\t\t\tif(!this.reconnectTimer)\n\t\t\t{\n\t\t\t\t// Attempt to reconnect after one keep-alive duration.\n\t\t\t\tthis.reconnectTimer = setTimeout(this.reconnect.bind(this), this.options.reconnectAfterMilliSeconds) as unknown as number;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Notify administrator of any unexpected errors.\n\t */\n\tonSocketError(error: any | undefined): void\n\t{\n\t\t// Report a generic error if no error information is present.\n\t\t// NOTE: When using WSS, the error event explicitly\n\t\t// only allows to send a \"simple\" event without data.\n\t\t// https://stackoverflow.com/a/18804298\n\t\tif(typeof error === 'undefined')\n\t\t{\n\t\t\t// Do nothing, and instead rely on the socket disconnect event for further information.\n\t\t\treturn;\n\t\t}\n\n\t\t// Log the error, as there is nothing we can do to actually handle it.\n\t\tdebug.errors(`Network error ('${this.hostIdentifier}'): `, error);\n\t}\n}\n","import { RPCParameter } from './rpc-interfaces';\n\n/**\n * Grouping of utilities that simplifies implementation of the Electrum protocol.\n *\n * @ignore\n */\nexport class ElectrumProtocol\n{\n\t/**\n\t * Helper function that builds an Electrum request object.\n\t *\n\t * @param method - method to call.\n\t * @param parameters - method parameters for the call.\n\t * @param requestId - unique string or number referencing this request.\n\t *\n\t * @returns a properly formatted Electrum request string.\n\t */\n\tstatic buildRequestObject(method: string, parameters: RPCParameter[], requestId: string | number): string\n\t{\n\t\t// Return the formatted request object.\n\t\t// NOTE: Electrum either uses JsonRPC strictly or loosely.\n\t\t// If we specify protocol identifier without being 100% compliant, we risk being disconnected/blacklisted.\n\t\t// For this reason, we omit the protocol identifier to avoid issues.\n\t\treturn JSON.stringify({ method: method, params: parameters, id: requestId });\n\t}\n\n\t/**\n\t * Constant used to verify if a provided string is a valid version number.\n\t *\n\t * @returns a regular expression that matches valid version numbers.\n\t */\n\tstatic get versionRegexp(): RegExp\n\t{\n\t\treturn /^\\d+(\\.\\d+)+$/;\n\t}\n\n\t/**\n\t * Constant used to separate statements/messages in a stream of data.\n\t *\n\t * @returns the delimiter used by Electrum to separate statements.\n\t */\n\tstatic get statementDelimiter(): string\n\t{\n\t\treturn '\\n';\n\t}\n}\n","import type { RPCError, RPCParameter, RPCResponse, RPCNotification } from './rpc-interfaces';\nimport type { EventEmitter } from 'eventemitter3';\n\n/**\n * Optional settings that change the default behavior of the network connection.\n */\nexport interface ElectrumNetworkOptions\n{\n\t/** If set to true, numbers that can safely be parsed as integers will be `BigInt` rather than `Number`. */\n\tuseBigInt?: boolean;\n\n\t/** When connected, send a keep-alive Ping message this often. */\n\tsendKeepAliveIntervalInMilliSeconds?: number;\n\n\t/** When disconnected, attempt to reconnect after this amount of time. */\n\treconnectAfterMilliSeconds?: number;\n\n\t/** After every send, verify that we have received data after this amount of time. */\n\tverifyConnectionTimeoutInMilliSeconds?: number;\n\n\t/** Turn off automatic handling of browser visibility, which disconnects when application is not visible to be consistent across browsers. */\n\tdisableBrowserVisibilityHandling?: boolean;\n\n\t/** Turn off automatic handling of browser connectivity. */\n\tdisableBrowserConnectivityHandling?: boolean;\n}\n\n/**\n * List of events emitted by the ElectrumSocket.\n * @event\n * @ignore\n */\nexport interface ElectrumSocketEvents\n{\n\t/**\n\t * Emitted when data has been received over the socket.\n\t * @eventProperty\n\t */\n\t'data': [ string ];\n\n\t/**\n\t * Emitted when a socket connects.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a socket disconnects.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when the socket has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * Abstract socket used when communicating with Electrum servers.\n */\nexport interface ElectrumSocket extends EventEmitter<ElectrumSocketEvents>, ElectrumSocketEvents\n{\n\t/**\n\t * Utility function to provide a human accessible host identifier.\n\t */\n\tget hostIdentifier(): string;\n\n\t/**\n\t * Fully qualified domain name or IP address of the host\n\t */\n\thost: string;\n\n\t/**\n\t * Network port for the host to connect to, defaults to the standard TLS port\n\t */\n\tport: number;\n\n\t/**\n\t * If false, uses an unencrypted connection instead of the default on TLS\n\t */\n\tencrypted: boolean;\n\n\t/**\n\t * If no connection is established after `timeout` ms, the connection is terminated\n\t */\n\ttimeout: number;\n\n\t/**\n\t * Connects to an Electrum server using the socket.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects from the Electrum server from the socket.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Write data to the Electrum server on the socket.\n\t *\n\t * @param data - Data to be written to the socket\n\t * @param callback - Callback function to be called when the write has completed\n\t */\n\twrite(data: Uint8Array | string, callback?: (err?: Error) => void): boolean;\n}\n\n/**\n * @ignore\n */\nexport interface VersionRejected\n{\n\terror: RPCError;\n}\n\n/**\n * @ignore\n */\nexport interface VersionNegotiated\n{\n\tsoftware: string;\n\tprotocol: string;\n}\n\n/**\n * @ignore\n */\nexport type VersionNegotiationResponse = VersionNegotiated | VersionRejected;\n\n/**\n * List of events emitted by the ElectrumConnection.\n * @event\n * @ignore\n */\nexport interface ElectrumConnectionEvents\n{\n\t/**\n\t * Emitted when any data has been received over the network.\n\t * @eventProperty\n\t */\n\t'received': [];\n\n\t/**\n\t * Emitted when a complete electrum message has been received over the network.\n\t * @eventProperty\n\t */\n\t'response': [ RPCResponse ];\n\n\t/**\n\t * Emitted when the connection has completed version negotiation.\n\t * @eventProperty\n\t */\n\t'version': [ VersionNegotiationResponse ];\n\n\t/**\n\t * Emitted when a network connection is initiated.\n\t * @eventProperty\n\t */\n\t'connecting': [];\n\n\t/**\n\t * Emitted when a network connection is successful.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a network disconnection is initiated.\n\t * @eventProperty\n\t */\n\t'disconnecting': [];\n\n\t/**\n\t * Emitted when a network disconnection is successful.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when a network connect attempts to automatically reconnect.\n\t * @eventProperty\n\t */\n\t'reconnecting': [];\n\n\t/**\n\t * Emitted when the network has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * List of events emitted by the ElectrumClient.\n * @event\n * @ignore\n */\nexport interface ElectrumClientEvents\n{\n\t/**\n\t * Emitted when an electrum subscription statement has been received over the network.\n\t * @eventProperty\n\t */\n\t'notification': [ RPCNotification ];\n\n\t/**\n\t * Emitted when a network connection is initiated.\n\t * @eventProperty\n\t */\n\t'connecting': [];\n\n\t/**\n\t * Emitted when a network connection is successful.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a network disconnection is initiated.\n\t * @eventProperty\n\t */\n\t'disconnecting': [];\n\n\t/**\n\t * Emitted when a network disconnection is successful.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when a network connect attempts to automatically reconnect.\n\t * @eventProperty\n\t */\n\t'reconnecting': [];\n\n\t/**\n\t * Emitted when the network has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * A list of possible responses to requests.\n * @ignore\n */\nexport type RequestResponse = RPCParameter | RPCParameter[];\n\n/**\n * Request resolvers are used to process the response of a request. This takes either\n * an error object or any stringified data, while the other parameter is omitted.\n * @ignore\n */\nexport type RequestResolver = (error?: Error, data?: string) => void;\n\n/**\n * Typing for promise resolution.\n * @ignore\n */\nexport type ResolveFunction<T> = (value: T | PromiseLike<T>) => void;\n\n/**\n * Typing for promise rejection.\n * @ignore\n */\nexport type RejectFunction = (reason?: any) => void;\n\n/**\n * @ignore\n */\nexport const isVersionRejected = function(object: any): object is VersionRejected\n{\n\treturn 'error' in object;\n};\n\n/**\n * @ignore\n */\nexport const isVersionNegotiated = function(object: any): object is VersionNegotiated\n{\n\treturn 'software' in object && 'protocol' in object;\n};\n","// Acceptable parameter types for RPC messages\nexport type RPCParameter = string | number | boolean | object | null;\n\n// Acceptable identifier types for RCP messages.\nexport type RCPIdentifier = number | string | null;\n\n// The base type for all RPC messages\nexport interface RPCBase\n{\n\tjsonrpc: string;\n}\n\n// An RPC message that sends a notification requiring no response\nexport interface RPCNotification extends RPCBase\n{\n\tmethod: string;\n\tparams?: RPCParameter[];\n}\n\n// An RPC message that sends a request requiring a response\nexport interface RPCRequest extends RPCBase\n{\n\tid: RCPIdentifier;\n\tmethod: string;\n\tparams?: RPCParameter[];\n}\n\n// An RPC message that returns the response to a successful request\nexport interface RPCStatement extends RPCBase\n{\n\tid: RCPIdentifier;\n\tresult: string;\n}\n\nexport interface RPCError\n{\n\tcode: number;\n\tmessage: string;\n\tdata?: any;\n}\n\n// An RPC message that returns the error to an unsuccessful request\nexport interface RPCErrorResponse extends RPCBase\n{\n\tid: RCPIdentifier;\n\terror: RPCError;\n}\n\n// A response to a request is either a statement (successful) or an error (unsuccessful)\nexport type RPCResponse = RPCErrorResponse | RPCStatement | RPCNotification;\n\n// RPC messages are notifications, requests, or responses\nexport type RPCMessage = RPCNotification | RPCRequest | RPCResponse;\n\n// Requests and responses can also be sent in batches\nexport type RPCResponseBatch = RPCResponse[];\nexport type RPCRequestBatch = RPCRequest[];\n\nexport const isRPCErrorResponse = function(message: RPCBase): message is RPCErrorResponse\n{\n\treturn 'id' in message && 'error' in message;\n};\n\nexport const isRPCStatement = function(message: RPCBase): message is RPCStatement\n{\n\treturn 'id' in message && 'result' in message;\n};\n\nexport const isRPCNotification = function(message: RPCBase): message is RPCNotification\n{\n\treturn !('id' in message) && 'method' in message;\n};\n\nexport const isRPCRequest = function(message: RPCBase): message is RPCRequest\n{\n\treturn 'id' in message && 'method' in message;\n};\n","// Disable indent rule for this file because it is broken (https://github.com/typescript-eslint/typescript-eslint/issues/1824)\n/* eslint-disable @typescript-eslint/indent */\n\n/**\n * Enum that denotes the connection status of an ElectrumConnection.\n * @enum {number}\n * @property {0} DISCONNECTED The connection is disconnected.\n * @property {1} AVAILABLE The connection is connected.\n * @property {2} DISCONNECTING The connection is disconnecting.\n * @property {3} CONNECTING The connection is connecting.\n * @property {4} RECONNECTING The connection is restarting.\n */\nexport enum ConnectionStatus\n{\n\tDISCONNECTED = 0,\n\tCONNECTED = 1,\n\tDISCONNECTING = 2,\n\tCONNECTING = 3,\n\tRECONNECTING = 4,\n}\n","import { ElectrumNetworkOptions } from './interfaces';\n\n// Define number of milliseconds per second for legibility.\nconst MILLI_SECONDS_PER_SECOND = 1000;\n\n/**\n * Configure default options.\n */\nexport const defaultNetworkOptions: ElectrumNetworkOptions =\n{\n\t// By default, all numbers including integers are parsed as regular JavaScript numbers.\n\tuseBigInt: false,\n\n\t// Send a ping message every seconds, to detect network problem as early as possible.\n\tsendKeepAliveIntervalInMilliSeconds: 1 * MILLI_SECONDS_PER_SECOND,\n\n\t// Try to reconnect 5 seconds after unintentional disconnects.\n\treconnectAfterMilliSeconds: 5 * MILLI_SECONDS_PER_SECOND,\n\n\t// Try to detect stale connections 5 seconds after every send.\n\tverifyConnectionTimeoutInMilliSeconds: 5 * MILLI_SECONDS_PER_SECOND,\n\n\t// Automatically manage the connection for a consistent behavior across browsers and devices.\n\tdisableBrowserVisibilityHandling: false,\n\tdisableBrowserConnectivityHandling: false,\n};\n"],"names":[],"version":3,"file":"index.mjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AGOO,MAAM;IAEZ;;;;;;;;EAQC,GACD,OAAO,mBAAmB,MAAc,EAAE,UAA0B,EAAE,SAA0B,EAChG;QACC,uCAAuC;QACvC,0DAA0D;QAC1D,gHAAgH;QAChH,0EAA0E;QAC1E,OAAO,KAAK,SAAS,CAAC;YAAE,QAAQ;YAAQ,QAAQ;YAAY,IAAI;QAAU;IAC3E;IAEA;;;;EAIC,GACD,WAAW,gBACX;QACC,OAAO;IACR;IAEA;;;;EAIC,GACD,WAAW,qBACX;QACC,OAAO;IACR;AACD;;;;;;;ACgOO,MAAM,4CAAoB,SAAS,MAAW;IAEpD,OAAO,WAAW;AACnB;AAKO,MAAM,4CAAsB,SAAS,MAAW;IAEtD,OAAO,cAAc,UAAU,cAAc;AAC9C;;;ACzRA,8CAA8C;AA0DvC,MAAM,2CAAqB,SAAS,OAAgB;IAE1D,OAAO,QAAQ,WAAW,WAAW;AACtC;AAEO,MAAM,4CAAiB,SAAS,OAAgB;IAEtD,OAAO,QAAQ,WAAW,YAAY;AACvC;AAEO,MAAM,4CAAoB,SAAS,OAAgB;IAEzD,OA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BAAgB,EAC3C;QACC,kDAAkD;QAClD,IAAG,iBAAiB,KAAK,EAExB,cAAc;QACd;QAGD,8BAA8B;QAC9B,IAAI,CAAC,QAAQ,GAAG,iBAAiB,QAAQ;IAC1C;IAEA;;;;EAIC,GACD,MAAM,8BACN;QACC,uDAAuD;QACvD,IAAI,CAAC,qBAAqB,GAAG,KAAK,GAAG;IACtC;IAEA;;;;;EAKC,GACD,MAAM,0CAA0C,OAAO,EACvD;QACC,4DAA4D;QAC5D,IAAG,QAAQ,MAAM,KAAK,gCAErB,iDAAiD;QACjD,IAAI,CAAC,WAAW,GAAG,QAAQ,MAAM,CAAC,EAAE,CAAC,MAAM;IAE7C;IAEA;;;;;EAKC,GACD,MAAM,qCAAqC,OAAO,EAClD;QACC,IACA;YACC,uDAAuD;YACvD,IAAG,OAAO,QAAQ,MAAM,CAAC,YAAY,KAAK,aAEzC,oCAAoC;YACpC,IAAI,CAAC,WAAW,GAAG,QAAQ,MAAM,CAAC,YAAY;QAEhD,EACA,OAAM,OACN;QACC,cAAc;QACf;IACD;IAEA;;EAEC,GACD,MAAM,8BAA8B,SAAS,EAC7C;QACC,qBAAqB;QACrB,IAAI,CAAC,IAAI,CAAC;IACX;AAUD;IAEA,qBAAqB;AACrB,2CAAe","sources":["source/index.ts","source/electrum-client.ts","source/electrum-connection.ts","source/electrum-protocol.ts","source/interfaces.ts","source/rpc-interfaces.ts","source/enums.ts","source/constants.ts"],"sourcesContent":["export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './enums';\n","import debug from '@electrum-cash/debug-logs';\nimport { ElectrumConnection } from './electrum-connection';\nimport { ElectrumProtocol } from './electrum-protocol';\nimport { defaultNetworkOptions } from './constants';\nimport { EventEmitter } from 'eventemitter3';\nimport { ConnectionStatus } from './enums';\nimport { RPCParameter, isRPCNotification, isRPCErrorResponse, RPCNotification, RPCResponse } from './rpc-interfaces';\nimport { Mutex } from 'async-mutex';\n\nimport type { ElectrumNetworkOptions, ElectrumClientEvents, ElectrumSocket, ResolveFunction, RequestResolver, RequestResponse } from './interfaces';\n\n/**\n * High-level Electrum client that lets applications send requests and subscribe to notification events from a server.\n */\nclass ElectrumClient<ElectrumEvents extends ElectrumClientEvents> extends EventEmitter<ElectrumClientEvents | ElectrumEvents> implements ElectrumClientEvents\n{\n\t/**\n\t * The name and version of the server software indexing the blockchain.\n\t */\n\tpublic software: string;\n\n\t/**\n\t * The genesis hash of the blockchain indexed by the server.\n\t * @remarks This is only available after a 'server.features' call.\n\t */\n\tpublic genesisHash: string;\n\n\t/**\n\t * The chain height of the blockchain indexed by the server.\n\t * @remarks This is only available after a 'blockchain.headers.subscribe' call.\n\t */\n\tpublic chainHeight: number;\n\n\t/**\n\t * Timestamp of when we last received data from the server indexing the blockchain.\n\t */\n\tpublic lastReceivedTimestamp: number;\n\n\t/**\n\t * Number corresponding to the underlying connection status.\n\t */\n\tpublic get status(): ConnectionStatus\n\t{\n\t\treturn this.connection.status;\n\t}\n\n\t// Declare instance variables\n\tprivate connection: ElectrumConnection;\n\n\t// Initialize an empty list of subscription metadata.\n\tprivate subscriptionMethods: Record<string, Set<string>> = {};\n\n\t// Start counting the request IDs from 0\n\tprivate requestId = 0;\n\n\t// Initialize an empty dictionary for keeping track of request resolvers\n\tprivate requestResolvers: { [index: number]: RequestResolver } = {};\n\n\t// Mutex lock used to prevent simultaneous connect() and disconnect() calls.\n\tprivate connectionLock = new Mutex();\n\n\t/**\n\t * Initializes an Electrum client.\n\t *\n\t * @param application - your application name, used to identify to the electrum host.\n\t * @param version - protocol version to use with the host.\n\t * @param socketOrHostname - pre-configured electrum socket or fully qualified domain name or IP number of the host\n\t * @param options - ...\n\t *\n\t * @throws {Error} if `version` is not a valid version string.\n\t */\n\tconstructor(\n\t\tpublic application: string,\n\t\tpublic version: string,\n\t\tpublic socketOrHostname: ElectrumSocket | string,\n\t\tpublic options: ElectrumNetworkOptions = {},\n\t)\n\t{\n\t\t// Initialize the event emitter.\n\t\tsuper();\n\n\t\t// Update default options with the provided values.\n\t\tconst networkOptions: ElectrumNetworkOptions = { ...defaultNetworkOptions, ...options };\n\n\t\t// Set up a connection to an electrum server.\n\t\tthis.connection = new ElectrumConnection(application, version, socketOrHostname, networkOptions);\n\t}\n\n\t// Expose hostIdentifier from the connection.\n\tget hostIdentifier(): string\n\t{\n\t\treturn this.connection.hostIdentifier;\n\t}\n\n\t// Expose port from the connection.\n\tget encrypted(): boolean\n\t{\n\t\treturn this.connection.encrypted;\n\t}\n\n\t/**\n\t * Connects to the remote server.\n\t *\n\t * @throws {Error} if the socket connection fails.\n\t * @returns a promise resolving when the connection is established.\n\t */\n\tasync connect(): Promise<void>\n\t{\n\t\t// Create a lock so that multiple connects/disconnects cannot race each other.\n\t\tconst unlock = await this.connectionLock.acquire();\n\n\t\ttry\n\t\t{\n\t\t\t// If we are already connected, do not attempt to connect again.\n\t\t\tif(this.connection.status === ConnectionStatus.CONNECTED)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Listen for parsed statements.\n\t\t\tthis.connection.on('response', this.response.bind(this));\n\n\t\t\t// Hook up handles for the connected and disconnected events.\n\t\t\tthis.connection.on('connected', this.resubscribeOnConnect.bind(this));\n\t\t\tthis.connection.on('disconnected', this.onConnectionDisconnect.bind(this));\n\n\t\t\t// Relay connecting and reconnecting events.\n\t\t\tthis.connection.on('connecting', this.handleConnectionStatusChanges.bind(this, 'connecting'));\n\t\t\tthis.connection.on('disconnecting', this.handleConnectionStatusChanges.bind(this, 'disconnecting'));\n\t\t\tthis.connection.on('reconnecting', this.handleConnectionStatusChanges.bind(this, 'reconnecting'));\n\n\t\t\t// Hook up client metadata gathering functions.\n\t\t\tthis.connection.on('version', this.storeSoftwareVersion.bind(this));\n\t\t\tthis.connection.on('received', this.updateLastReceivedTimestamp.bind(this));\n\n\t\t\t// Relay error events.\n\t\t\tthis.connection.on('error', this.emit.bind(this, 'error'));\n\n\t\t\t// Connect with the server.\n\t\t\tawait this.connection.connect();\n\t\t}\n\t\t// Always release our lock so that we do not end up in a stuck-state.\n\t\tfinally\n\t\t{\n\t\t\tunlock();\n\t\t}\n\t}\n\n\t/**\n\t * Disconnects from the remote server and removes all event listeners/subscriptions and open requests.\n\t *\n\t * @param force - disconnect even if the connection has not been fully established yet.\n\t * @param retainSubscriptions - retain subscription data so they will be restored on reconnection.\n\t *\n\t * @returns true if successfully disconnected, or false if there was no connection.\n\t */\n\tasync disconnect(force: boolean = false, retainSubscriptions: boolean = false): Promise<boolean>\n\t{\n\t\tif(!retainSubscriptions)\n\t\t{\n\t\t\t// Cancel all event listeners.\n\t\t\tthis.removeAllListeners();\n\n\t\t\t// Remove all subscription data\n\t\t\tthis.subscriptionMethods = {};\n\t\t}\n\n\t\t// Disconnect from the remote server.\n\t\treturn this.connection.disconnect(force);\n\t}\n\n\t/**\n\t * Calls a method on the remote server with the supplied parameters.\n\t *\n\t * @param method - name of the method to call.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise that resolves with the result of the method or an Error.\n\t */\n\tasync request(method: string, ...parameters: RPCParameter[]): Promise<Error | RequestResponse>\n\t{\n\t\t// If we are not connected to a server..\n\t\tif(this.connection.status !== ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\t// Reject the request with a disconnected error message.\n\t\t\tthrow(new Error(`Unable to send request to a disconnected server '${this.hostIdentifier}'.`));\n\t\t}\n\n\t\t// Increase the request ID by one.\n\t\tthis.requestId += 1;\n\n\t\t// Store a copy of the request id.\n\t\tconst id = this.requestId;\n\n\t\t// Format the arguments as an electrum request object.\n\t\tconst message = ElectrumProtocol.buildRequestObject(method, parameters, id);\n\n\t\t// Define a function to wrap the request in a promise.\n\t\tconst requestResolver = (resolve: ResolveFunction<Error | RequestResponse>): void =>\n\t\t{\n\t\t\t// Add a request resolver for this promise to the list of requests.\n\t\t\tthis.requestResolvers[id] = (error?: Error, data?: RequestResponse) =>\n\t\t\t{\n\t\t\t\t// If the resolution failed..\n\t\t\t\tif(error)\n\t\t\t\t{\n\t\t\t\t\t// Resolve the promise with the error for the application to handle.\n\t\t\t\t\tresolve(error);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t// Resolve the promise with the request results.\n\t\t\t\t\tresolve(data);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Send the request message to the remote server.\n\t\t\tthis.connection.send(message);\n\t\t};\n\n\t\t// Write a log message.\n\t\tdebug.network(`Sending request '${method}' to '${this.hostIdentifier}'`);\n\n\t\t// return a promise to deliver results later.\n\t\treturn new Promise<Error | RequestResponse>(requestResolver);\n\t}\n\n\t/**\n\t * Subscribes to the method and payload at the server.\n\t *\n\t * @remarks the response for the subscription request is issued as a notification event.\n\t *\n\t * @param method - one of the subscribable methods the server supports.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving when the subscription is established.\n\t */\n\tasync subscribe(method: string, ...parameters: RPCParameter[]): Promise<void>\n\t{\n\t\t// Initialize an empty list of subscription payloads, if needed.\n\t\tif(!this.subscriptionMethods[method])\n\t\t{\n\t\t\tthis.subscriptionMethods[method] = new Set<string>();\n\t\t}\n\n\t\t// Store the subscription parameters to track what data we have subscribed to.\n\t\tthis.subscriptionMethods[method].add(JSON.stringify(parameters));\n\n\t\t// Send initial subscription request.\n\t\tconst requestData = await this.request(method, ...parameters);\n\n\t\t// If the request failed, throw it as an error.\n\t\tif(requestData instanceof Error)\n\t\t{\n\t\t\tthrow(requestData);\n\t\t}\n\n\t\t// If the request returned more than one data point..\n\t\tif(Array.isArray(requestData))\n\t\t{\n\t\t\t// .. throw an error, as this breaks our expectation for subscriptions.\n\t\t\tthrow(new Error('Subscription request returned an more than one data point.'));\n\t\t}\n\n\t\t// Construct a notification structure to package the initial result as a notification.\n\t\tconst notification: RPCNotification =\n\t\t{\n\t\t\tjsonrpc: '2.0',\n\t\t\tmethod: method,\n\t\t\tparams: [ ...parameters, requestData ],\n\t\t};\n\n\t\t// Manually emit an event for the initial response.\n\t\tthis.emit('notification', notification);\n\n\t\t// Try to update the chain height.\n\t\tthis.updateChainHeightFromHeadersNotifications(notification);\n\t}\n\n\t/**\n\t * Unsubscribes to the method at the server and removes any callback functions\n\t * when there are no more subscriptions for the method.\n\t *\n\t * @param method - a previously subscribed to method.\n\t * @param parameters - one or more parameters for the method.\n\t *\n\t * @throws {Error} if no subscriptions exist for the combination of the provided `method` and `parameters.\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving when the subscription is removed.\n\t */\n\tasync unsubscribe(method: string, ...parameters: RPCParameter[]): Promise<void>\n\t{\n\t\t// Throw an error if the client is disconnected.\n\t\tif(this.connection.status !== ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\tthrow(new Error(`Unable to send unsubscribe request to a disconnected server '${this.hostIdentifier}'.`));\n\t\t}\n\n\t\t// If this method has no subscriptions..\n\t\tif(!this.subscriptionMethods[method])\n\t\t{\n\t\t\t// Reject this promise with an explanation.\n\t\t\tthrow(new Error(`Cannot unsubscribe from '${method}' since the method has no subscriptions.`));\n\t\t}\n\n\t\t// Pack up the parameters as a long string.\n\t\tconst subscriptionParameters = JSON.stringify(parameters);\n\n\t\t// If the method payload could not be located..\n\t\tif(!this.subscriptionMethods[method].has(subscriptionParameters))\n\t\t{\n\t\t\t// Reject this promise with an explanation.\n\t\t\tthrow(new Error(`Cannot unsubscribe from '${method}' since it has no subscription with the given parameters.`));\n\t\t}\n\n\t\t// Remove this specific subscription payload from internal tracking.\n\t\tthis.subscriptionMethods[method].delete(subscriptionParameters);\n\n\t\t// Send unsubscription request to the server\n\t\t// NOTE: As a convenience we allow users to define the method as the subscribe or unsubscribe version.\n\t\tawait this.request(method.replace('.subscribe', '.unsubscribe'), ...parameters);\n\n\t\t// Write a log message.\n\t\tdebug.client(`Unsubscribed from '${String(method)}' for the '${subscriptionParameters}' parameters.`);\n\t}\n\n\t/**\n\t * Restores existing subscriptions without updating status or triggering manual callbacks.\n\t *\n\t * @throws {Error} if subscription data cannot be found for all stored event names.\n\t * @throws {Error} if the client is disconnected.\n\t * @returns a promise resolving to true when the subscriptions are restored.\n\t *\n\t * @ignore\n\t */\n\tprivate async resubscribeOnConnect(): Promise<void>\n\t{\n\t\t// Write a log message.\n\t\tdebug.client(`Connected to '${this.hostIdentifier}'.`);\n\n\t\t// Synchronize with the underlying connection status.\n\t\tthis.handleConnectionStatusChanges('connected');\n\n\t\t// Initialize an empty list of resubscription promises.\n\t\tconst resubscriptionPromises = [];\n\n\t\t// For each method we have a subscription for..\n\t\tfor(const method in this.subscriptionMethods)\n\t\t{\n\t\t\t// .. and for each parameter we have previously been subscribed to..\n\t\t\tfor(const parameterJSON of this.subscriptionMethods[method].values())\n\t\t\t{\n\t\t\t\t// restore the parameters from JSON.\n\t\t\t\tconst parameters = JSON.parse(parameterJSON);\n\n\t\t\t\t// Send a subscription request.\n\t\t\t\tresubscriptionPromises.push(this.subscribe(method, ...parameters));\n\t\t\t}\n\n\t\t\t// Wait for all re-subscriptions to complete.\n\t\t\tawait Promise.all(resubscriptionPromises);\n\t\t}\n\n\t\t// Write a log message if there was any subscriptions to restore.\n\t\tif(resubscriptionPromises.length > 0)\n\t\t{\n\t\t\tdebug.client(`Restored ${resubscriptionPromises.length} previous subscriptions for '${this.hostIdentifier}'`);\n\t\t}\n\t}\n\n\t/**\n\t * Parser messages from the remote server to resolve request promises and emit subscription events.\n\t *\n\t * @param message - the response message\n\t *\n\t * @throws {Error} if the message ID does not match an existing request.\n\t * @ignore\n\t */\n\tresponse(message: RPCResponse): void\n\t{\n\t\t// If the received message is a notification, we forward it to all event listeners\n\t\tif(isRPCNotification(message))\n\t\t{\n\t\t\t// Write a log message.\n\t\t\tdebug.client(`Received notification for '${message.method}' from '${this.hostIdentifier}'`);\n\n\t\t\t// Forward the message content to all event listeners.\n\t\t\tthis.emit('notification', message);\n\n\t\t\t// Try to update the chain height.\n\t\t\tthis.updateChainHeightFromHeadersNotifications(message);\n\n\t\t\t// Return since it does not have an associated request resolver\n\t\t\treturn;\n\t\t}\n\n\t\t// If the response ID is null we cannot use it to index our request resolvers\n\t\tif(message.id === null)\n\t\t{\n\t\t\t// Throw an internal error, this should not happen.\n\t\t\tthrow(new Error('Internal error: Received an RPC response with ID null.'));\n\t\t}\n\n\t\t// Look up which request promise we should resolve this.\n\t\tconst requestResolver = this.requestResolvers[message.id];\n\n\t\t// If we do not have a request resolver for this response message..\n\t\tif(!requestResolver)\n\t\t{\n\t\t\t// Log that a message was ignored since the request has already been rejected.\n\t\t\tdebug.warning(`Ignoring response #${message.id} as the request has already been rejected.`);\n\n\t\t\t// Return as this has now been fully handled.\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove the promise from the request list.\n\t\tdelete this.requestResolvers[message.id];\n\n\t\t// If the message contains an error..\n\t\tif(isRPCErrorResponse(message))\n\t\t{\n\t\t\t// Forward the message error to the request resolver and omit the `result` parameter.\n\t\t\trequestResolver(new Error(message.error.message));\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Forward the message content to the request resolver and omit the `error` parameter\n\t\t\t// (by setting it to undefined).\n\t\t\trequestResolver(undefined, message.result);\n\n\t\t\t// Attempt to extract genesis hash from feature requests.\n\t\t\tthis.storeGenesisHashFromFeaturesResponse(message);\n\t\t}\n\t}\n\n\t/**\n\t * Callback function that is called when connection to the Electrum server is lost.\n\t * Aborts all active requests with an error message indicating that connection was lost.\n\t *\n\t * @ignore\n\t */\n\tasync onConnectionDisconnect(): Promise<void>\n\t{\n\t\t// Loop over active requests\n\t\tfor(const resolverId in this.requestResolvers)\n\t\t{\n\t\t\t// Extract request resolver for readability\n\t\t\tconst requestResolver = this.requestResolvers[resolverId];\n\n\t\t\t// Resolve the active request with an error indicating that the connection was lost.\n\t\t\trequestResolver(new Error('Connection lost'));\n\n\t\t\t// Remove the promise from the request list.\n\t\t\tdelete this.requestResolvers[resolverId];\n\t\t}\n\n\t\t// Synchronize with the underlying connection status.\n\t\tthis.handleConnectionStatusChanges('disconnected');\n\t}\n\n\t/**\n\t * Stores the server provider software version field on successful version negotiation.\n\t *\n\t * @ignore\n\t */\n\tasync storeSoftwareVersion(versionStatement): Promise<void>\n\t{\n\t\t// TODO: handle failed version negotiation better.\n\t\tif(versionStatement.error)\n\t\t{\n\t\t\t// Do nothing.\n\t\t\treturn;\n\t\t}\n\n\t\t// Store the software version.\n\t\tthis.software = versionStatement.software;\n\t}\n\n\t/**\n\t * Updates the last received timestamp.\n\t *\n\t * @ignore\n\t */\n\tasync updateLastReceivedTimestamp(): Promise<void>\n\t{\n\t\t// Update the timestamp for when we last received data.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\t}\n\n\t/**\n\t * Checks if the provided message is a response to a headers subscription,\n\t * and if so updates the locally stored chain height value for this client.\n\t *\n\t * @ignore\n\t */\n\tasync updateChainHeightFromHeadersNotifications(message): Promise<void>\n\t{\n\t\t// If the message is a notification for a new chain height..\n\t\tif(message.method === 'blockchain.headers.subscribe')\n\t\t{\n\t\t\t// ..also store the updated chain height locally.\n\t\t\tthis.chainHeight = message.params[0].height;\n\t\t}\n\t}\n\n\t/**\n\t * Checks if the provided message is a response to a server.features request,\n\t * and if so stores the genesis hash for this client locally.\n\t *\n\t * @ignore\n\t */\n\tasync storeGenesisHashFromFeaturesResponse(message): Promise<void>\n\t{\n\t\ttry\n\t\t{\n\t\t\t// If the message is a response to a features request..\n\t\t\tif(typeof message.result.genesis_hash !== 'undefined')\n\t\t\t{\n\t\t\t\t// ..store the genesis hash locally.\n\t\t\t\tthis.genesisHash = message.result.genesis_hash;\n\t\t\t}\n\t\t}\n\t\tcatch(error)\n\t\t{\n\t\t\t// Do nothing.\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to synchronize state and events with the underlying connection.\n\t */\n\tasync handleConnectionStatusChanges(eventName): Promise<void>\n\t{\n\t\t// Re-emit the event.\n\t\tthis.emit(eventName);\n\t}\n\n\t// Add magic glue that makes typedoc happy so that we can have the events listed on the class.\n\tpublic readonly connecting: [];\n\tpublic readonly connected: [];\n\tpublic readonly disconnecting: [];\n\tpublic readonly disconnected: [];\n\tpublic readonly reconnecting: [];\n\tpublic readonly notification: [ RPCNotification ];\n\tpublic readonly error: [ Error ];\n}\n\n// Export the client.\nexport default ElectrumClient;\n","import debug from '@electrum-cash/debug-logs';\nimport { ElectrumWebSocket } from '@electrum-cash/web-socket';\nimport { ElectrumProtocol } from './electrum-protocol';\nimport { ElectrumNetworkOptions, ElectrumConnectionEvents, ElectrumSocket, ResolveFunction, RejectFunction, VersionNegotiationResponse, isVersionRejected } from './interfaces';\nimport { isRPCNotification, isRPCErrorResponse, RPCResponse, RPCErrorResponse } from './rpc-interfaces';\nimport { EventEmitter } from 'eventemitter3';\nimport { ConnectionStatus } from './enums';\nimport { parse, parseNumberAndBigInt } from 'lossless-json';\n\n/**\n * Wrapper around TLS/WSS sockets that gracefully separates a network stream into Electrum protocol messages.\n */\nexport class ElectrumConnection extends EventEmitter<ElectrumConnectionEvents>\n{\n\t// Initialize the connected flag to false to indicate that there is no connection\n\tpublic status: ConnectionStatus = ConnectionStatus.DISCONNECTED;\n\n\t// Declare empty timestamps\n\tprivate lastReceivedTimestamp: number;\n\n\t// Declare an empty socket.\n\tprivate socket: ElectrumSocket;\n\n\t// Declare timers for keep-alive pings and reconnection\n\tprivate keepAliveTimer?: number;\n\tprivate reconnectTimer?: number;\n\n\t// Initialize an empty array of connection verification timers.\n\tprivate verifications: Array<number> = [];\n\n\t// Initialize messageBuffer to an empty string\n\tprivate messageBuffer = '';\n\n\t/**\n\t * Sets up network configuration for an Electrum client connection.\n\t *\n\t * @param application - your application name, used to identify to the electrum host.\n\t * @param version - protocol version to use with the host.\n\t * @param socketOrHostname - pre-configured electrum socket or fully qualified domain name or IP number of the host\n\t * @param options - ...\n\t *\n\t * @throws {Error} if `version` is not a valid version string.\n\t */\n\tconstructor(\n\t\tprivate application: string,\n\t\tprivate version: string,\n\t\tprivate socketOrHostname: ElectrumSocket | string,\n\t\tprivate options: ElectrumNetworkOptions,\n\t)\n\t{\n\t\t// Initialize the event emitter.\n\t\tsuper();\n\n\t\t// Check if the provided version is a valid version number.\n\t\tif(!ElectrumProtocol.versionRegexp.test(version))\n\t\t{\n\t\t\t// Throw an error since the version number was not valid.\n\t\t\tthrow(new Error(`Provided version string (${version}) is not a valid protocol version number.`));\n\t\t}\n\n\t\t// If a hostname was provided..\n\t\tif(typeof socketOrHostname === 'string')\n\t\t{\n\t\t\t// Use a web socket with default parameters.\n\t\t\tthis.socket = new ElectrumWebSocket(socketOrHostname);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Use the provided socket.\n\t\t\tthis.socket = socketOrHostname;\n\t\t}\n\n\t\t// Set up handlers for connection and disconnection.\n\t\tthis.socket.on('connected', this.onSocketConnect.bind(this));\n\t\tthis.socket.on('disconnected', this.onSocketDisconnect.bind(this));\n\n\t\t// Set up handler for incoming data.\n\t\tthis.socket.on('data', this.parseMessageChunk.bind(this));\n\n\t\t// Handle visibility changes when run in a browser environment (if not explicitly disabled).\n\t\tif(typeof document !== 'undefined' && !this.options.disableBrowserVisibilityHandling)\n\t\t{\n\t\t\tdocument.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));\n\t\t}\n\n\t\t// Handle network connection changes when run in a browser environment (if not explicitly disabled).\n\t\tif(typeof window !== 'undefined' && !this.options.disableBrowserConnectivityHandling)\n\t\t{\n\t\t\twindow.addEventListener('online', this.handleNetworkChange.bind(this));\n\t\t\twindow.addEventListener('offline', this.handleNetworkChange.bind(this));\n\t\t}\n\t}\n\n\t// Expose hostIdentifier from the socket.\n\tget hostIdentifier(): string\n\t{\n\t\treturn this.socket.hostIdentifier;\n\t}\n\n\t// Expose port from the socket.\n\tget encrypted(): boolean\n\t{\n\t\treturn this.socket.encrypted;\n\t}\n\n\t/**\n\t * Assembles incoming data into statements and hands them off to the message parser.\n\t *\n\t * @param data - data to append to the current message buffer, as a string.\n\t *\n\t * @throws {SyntaxError} if the passed statement parts are not valid JSON.\n\t */\n\tparseMessageChunk(data: string): void\n\t{\n\t\t// Update the timestamp for when we last received data.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\n\t\t// Emit a notification indicating that the connection has received data.\n\t\tthis.emit('received');\n\n\t\t// Clear and remove all verification timers.\n\t\tthis.verifications.forEach((timer) => clearTimeout(timer));\n\t\tthis.verifications.length = 0;\n\n\t\t// Add the message to the current message buffer.\n\t\tthis.messageBuffer += data;\n\n\t\t// Check if the new message buffer contains the statement delimiter.\n\t\twhile(this.messageBuffer.includes(ElectrumProtocol.statementDelimiter))\n\t\t{\n\t\t\t// Split message buffer into statements.\n\t\t\tconst statementParts = this.messageBuffer.split(ElectrumProtocol.statementDelimiter);\n\n\t\t\t// For as long as we still have statements to parse..\n\t\t\twhile(statementParts.length > 1)\n\t\t\t{\n\t\t\t\t// Move the first statement to its own variable.\n\t\t\t\tconst currentStatementList = String(statementParts.shift());\n\n\t\t\t\t// Parse the statement into an object or list of objects.\n\t\t\t\tlet statementList = parse(currentStatementList, null, this.options.useBigInt ? parseNumberAndBigInt : parseFloat) as RPCResponse | RPCResponse[];\n\n\t\t\t\t// Wrap the statement in an array if it is not already a batched statement list.\n\t\t\t\tif(!Array.isArray(statementList))\n\t\t\t\t{\n\t\t\t\t\tstatementList = [ statementList ];\n\t\t\t\t}\n\n\t\t\t\t// For as long as there is statements in the result set..\n\t\t\t\twhile(statementList.length > 0)\n\t\t\t\t{\n\t\t\t\t\t// Move the first statement from the batch to its own variable.\n\t\t\t\t\tconst currentStatement = statementList.shift();\n\n\t\t\t\t\t// If the current statement is a subscription notification..\n\t\t\t\t\tif(isRPCNotification(currentStatement))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Emit the notification for handling higher up in the stack.\n\t\t\t\t\t\tthis.emit('response', currentStatement);\n\n\t\t\t\t\t\t// Consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the current statement is a version negotiation response..\n\t\t\t\t\tif(currentStatement.id === 'versionNegotiation')\n\t\t\t\t\t{\n\t\t\t\t\t\tif(isRPCErrorResponse(currentStatement))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// Then emit a failed version negotiation response signal.\n\t\t\t\t\t\t\tthis.emit('version', { error: currentStatement.error });\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// Extract the software and protocol version reported.\n\t\t\t\t\t\t\tconst [ software, protocol ] = currentStatement.result;\n\n\t\t\t\t\t\t\t// Emit a successful version negotiation response signal.\n\t\t\t\t\t\t\tthis.emit('version', { software, protocol });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If the current statement is a keep-alive response..\n\t\t\t\t\tif(currentStatement.id === 'keepAlive')\n\t\t\t\t\t{\n\t\t\t\t\t\t// Do nothing and consider this statement handled.\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Emit the statements for handling higher up in the stack.\n\t\t\t\t\tthis.emit('response', currentStatement);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Store the remaining statement as the current message buffer.\n\t\t\tthis.messageBuffer = statementParts.shift() || '';\n\t\t}\n\t}\n\n\t/**\n\t * Sends a keep-alive message to the host.\n\t *\n\t * @returns true if the ping message was fully flushed to the socket, false if\n\t * part of the message is queued in the user memory\n\t */\n\tping(): boolean\n\t{\n\t\t// Write a log message.\n\t\tdebug.ping(`Sending keep-alive ping to '${this.hostIdentifier}'`);\n\n\t\t// Craft a keep-alive message.\n\t\tconst message = ElectrumProtocol.buildRequestObject('server.ping', [], 'keepAlive');\n\n\t\t// Send the keep-alive message.\n\t\tconst status = this.send(message);\n\n\t\t// Return the ping status.\n\t\treturn status;\n\t}\n\n\t/**\n\t * Initiates the network connection negotiates a protocol version. Also emits the 'connect' signal if successful.\n\t *\n\t * @throws {Error} if the socket connection fails.\n\t * @returns a promise resolving when the connection is established\n\t */\n\tasync connect(): Promise<void>\n\t{\n\t\t// If we are already connected return true.\n\t\tif(this.status === ConnectionStatus.CONNECTED)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Indicate that the connection is connecting\n\t\tthis.status = ConnectionStatus.CONNECTING;\n\n\t\t// Emit a connect event now that the connection is being set up.\n\t\tthis.emit('connecting');\n\n\t\t// Define a function to wrap connection as a promise.\n\t\tconst connectionResolver = (resolve: ResolveFunction<void>, reject: RejectFunction): void =>\n\t\t{\n\t\t\tconst rejector = (error: Error): void =>\n\t\t\t{\n\t\t\t\t// Set the status back to disconnected\n\t\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t\t// Emit a connect event indicating that we failed to connect.\n\t\t\t\tthis.emit('disconnected');\n\n\t\t\t\t// Reject with the error as reason\n\t\t\t\treject(error);\n\t\t\t};\n\n\t\t\t// Replace previous error handlers to reject the promise on failure.\n\t\t\tthis.socket.removeAllListeners('error');\n\t\t\tthis.socket.once('error', rejector);\n\n\t\t\t// Define a function to wrap version negotiation as a callback.\n\t\t\tconst versionNegotiator = (): void =>\n\t\t\t{\n\t\t\t\t// Write a log message to show that we have started version negotiation.\n\t\t\t\tdebug.network(`Requesting protocol version ${this.version} with '${this.hostIdentifier}'.`);\n\n\t\t\t\t// remove the one-time error handler since no error was detected.\n\t\t\t\tthis.socket.removeListener('error', rejector);\n\n\t\t\t\t// Build a version negotiation message.\n\t\t\t\tconst versionMessage = ElectrumProtocol.buildRequestObject('server.version', [ this.application, this.version ], 'versionNegotiation');\n\n\t\t\t\t// Define a function to wrap version validation as a function.\n\t\t\t\tconst versionValidator = (version: VersionNegotiationResponse): void =>\n\t\t\t\t{\n\t\t\t\t\t// Check if version negotiation failed.\n\t\t\t\t\tif(isVersionRejected(version))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Disconnect from the host.\n\t\t\t\t\t\tthis.disconnect(true);\n\n\t\t\t\t\t\t// Declare an error message.\n\t\t\t\t\t\tconst errorMessage = 'unsupported protocol version.';\n\n\t\t\t\t\t\t// Log the error.\n\t\t\t\t\t\tdebug.errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);\n\n\t\t\t\t\t\t// Reject the connection with false since version negotiation failed.\n\t\t\t\t\t\treject(errorMessage);\n\t\t\t\t\t}\n\t\t\t\t\t// Check if the host supports our requested protocol version.\n\t\t\t\t\t// NOTE: the server responds with version numbers that truncate 0's, so 1.5.0 turns into 1.5.\n\t\t\t\t\telse if((version.protocol !== this.version) && (`${version.protocol}.0` !== this.version) && (`${version.protocol}.0.0` !== this.version))\n\t\t\t\t\t{\n\t\t\t\t\t\t// Disconnect from the host.\n\t\t\t\t\t\tthis.disconnect(true);\n\n\t\t\t\t\t\t// Declare an error message.\n\t\t\t\t\t\tconst errorMessage = `incompatible protocol version negotiated (${version.protocol} !== ${this.version}).`;\n\n\t\t\t\t\t\t// Log the error.\n\t\t\t\t\t\tdebug.errors(`Failed to connect with ${this.hostIdentifier} due to ${errorMessage}`);\n\n\t\t\t\t\t\t// Reject the connection with false since version negotiation failed.\n\t\t\t\t\t\treject(errorMessage);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t// Write a log message.\n\t\t\t\t\t\tdebug.network(`Negotiated protocol version ${version.protocol} with '${this.hostIdentifier}', powered by ${version.software}.`);\n\n\t\t\t\t\t\t// Set connection status to connected\n\t\t\t\t\t\tthis.status = ConnectionStatus.CONNECTED;\n\n\t\t\t\t\t\t// Emit a connect event now that the connection is usable.\n\t\t\t\t\t\tthis.emit('connected');\n\n\t\t\t\t\t\t// Resolve the connection promise since we successfully connected and negotiated protocol version.\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t// Listen for version negotiation once.\n\t\t\t\tthis.once('version', versionValidator);\n\n\t\t\t\t// Send the version negotiation message.\n\t\t\t\tthis.send(versionMessage);\n\t\t\t};\n\n\t\t\t// Prepare the version negotiation.\n\t\t\tthis.socket.once('connected', versionNegotiator);\n\n\t\t\t// Set up handler for network errors.\n\t\t\tthis.socket.on('error', this.onSocketError.bind(this));\n\n\t\t\t// Connect to the server.\n\t\t\tthis.socket.connect();\n\t\t};\n\n\t\t// Wait until connection is established and version negotiation succeeds.\n\t\tawait new Promise<void>(connectionResolver);\n\t}\n\n\t/**\n\t * Restores the network connection.\n\t */\n\tasync reconnect(): Promise<void>\n\t{\n\t\t// If a reconnect timer is set, remove it\n\t\tawait this.clearReconnectTimer();\n\n\t\t// Write a log message.\n\t\tdebug.network(`Trying to reconnect to '${this.hostIdentifier}'..`);\n\n\t\t// Set the status to reconnecting for more accurate log messages.\n\t\tthis.status = ConnectionStatus.RECONNECTING;\n\n\t\t// Emit a connect event now that the connection is usable.\n\t\tthis.emit('reconnecting');\n\n\t\t// Disconnect the underlying socket.\n\t\tthis.socket.disconnect();\n\n\t\ttry\n\t\t{\n\t\t\t// Try to connect again.\n\t\t\tawait this.connect();\n\t\t}\n\t\tcatch(error)\n\t\t{\n\t\t\t// Do nothing as the error should be handled via the disconnect and error signals.\n\t\t}\n\t}\n\n\t/**\n\t * Removes the current reconnect timer.\n\t */\n\tclearReconnectTimer(): void\n\t{\n\t\t// If a reconnect timer is set, remove it\n\t\tif(this.reconnectTimer)\n\t\t{\n\t\t\tclearTimeout(this.reconnectTimer);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.reconnectTimer = undefined;\n\t}\n\n\t/**\n\t * Removes the current keep-alive timer.\n\t */\n\tclearKeepAliveTimer(): void\n\t{\n\t\t// If a keep-alive timer is set, remove it\n\t\tif(this.keepAliveTimer)\n\t\t{\n\t\t\tclearTimeout(this.keepAliveTimer);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.keepAliveTimer = undefined;\n\t}\n\n\t/**\n\t * Initializes the keep alive timer loop.\n\t */\n\tsetupKeepAliveTimer(): void\n\t{\n\t\t// If the keep-alive timer loop is not currently set up..\n\t\tif(!this.keepAliveTimer)\n\t\t{\n\t\t\t// Set a new keep-alive timer.\n\t\t\tthis.keepAliveTimer = setTimeout(this.ping.bind(this), this.options.sendKeepAliveIntervalInMilliSeconds) as unknown as number;\n\t\t}\n\t}\n\n\t/**\n\t * Tears down the current connection and removes all event listeners on disconnect.\n\t *\n\t * @param force - disconnect even if the connection has not been fully established yet.\n\t * @param intentional - update connection state if disconnect is intentional.\n\t *\n\t * @returns true if successfully disconnected, or false if there was no connection.\n\t */\n\tasync disconnect(force: boolean = false, intentional: boolean = true): Promise<boolean>\n\t{\n\t\t// Return early when there is nothing to disconnect from\n\t\tif(this.status === ConnectionStatus.DISCONNECTED && !force)\n\t\t{\n\t\t\t// Return false to indicate that there was nothing to disconnect from.\n\t\t\treturn false;\n\t\t}\n\n\t\t// Update connection state if the disconnection is intentional.\n\t\t// NOTE: The state is meant to represent what the client is requesting, but\n\t\t// is used internally to handle visibility changes in browsers to ensure functional reconnection.\n\t\tif(intentional)\n\t\t{\n\t\t\t// Set connection status to null to indicate tear-down is currently happening.\n\t\t\tthis.status = ConnectionStatus.DISCONNECTING;\n\t\t}\n\n\t\t// Emit a connect event to indicate that we are disconnecting.\n\t\tthis.emit('disconnecting');\n\n\t\t// If a keep-alive timer is set, remove it.\n\t\tawait this.clearKeepAliveTimer();\n\n\t\t// If a reconnect timer is set, remove it\n\t\tawait this.clearReconnectTimer();\n\n\t\tconst disconnectResolver = (resolve: ResolveFunction<boolean>): void =>\n\t\t{\n\t\t\t// Resolve to true after the connection emits a disconnect\n\t\t\tthis.once('disconnected', () => resolve(true));\n\n\t\t\t// Close the connection on the socket level.\n\t\t\tthis.socket.disconnect();\n\t\t};\n\n\t\t// Return true to indicate that we disconnected.\n\t\treturn new Promise<boolean>(disconnectResolver);\n\t}\n\n\t/**\n\t * Updates the connection state based on browser reported connectivity.\n\t *\n\t * Most modern browsers are able to provide information on the connection state\n\t * which allows for significantly faster response times to network changes compared\n\t * to waiting for network requests to fail.\n\t *\n\t * When available, we make use of this to fail early to provide a better user experience.\n\t */\n\tasync handleNetworkChange(): Promise<void>\n\t{\n\t\t// Do nothing if we do not have the navigator available.\n\t\tif(typeof window.navigator === 'undefined')\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Attempt to reconnect to the network now that we may be online again.\n\t\tif(window.navigator.onLine === true)\n\t\t{\n\t\t\tthis.reconnect();\n\t\t}\n\n\t\t// Disconnected from the network so that cleanup can happen while we're offline.\n\t\tif(window.navigator.onLine !== true)\n\t\t{\n\t\t\tconst forceDisconnect = true;\n\t\t\tconst isIntentional = true;\n\n\t\t\tthis.disconnect(forceDisconnect, isIntentional);\n\t\t}\n\t}\n\n\t/**\n\t * Updates connection state based on application visibility.\n\t *\n\t * Some browsers will disconnect network connections when the browser is out of focus,\n\t * which would normally cause our reconnect-on-timeout routines to trigger, but that\n\t * results in a poor user experience since the events are not handled consistently\n\t * and sometimes it can take some time after restoring focus to the browser.\n\t *\n\t * By manually disconnecting when this happens we prevent the default reconnection routines\n\t * and make the behavior consistent across browsers.\n\t */\n\tasync handleVisibilityChange(): Promise<void>\n\t{\n\t\t// Disconnect when application is removed from focus.\n\t\tif(document.visibilityState === 'hidden')\n\t\t{\n\t\t\tconst forceDisconnect = true;\n\t\t\tconst isIntentional = true;\n\n\t\t\tthis.disconnect(forceDisconnect, isIntentional);\n\t\t}\n\n\t\t// Reconnect when application is returned to focus.\n\t\tif(document.visibilityState === 'visible')\n\t\t{\n\t\t\tthis.reconnect();\n\t\t}\n\t}\n\n\t/**\n\t * Sends an arbitrary message to the server.\n\t *\n\t * @param message - json encoded request object to send to the server, as a string.\n\t *\n\t * @returns true if the message was fully flushed to the socket, false if part of the message\n\t * is queued in the user memory\n\t */\n\tsend(message: string): boolean\n\t{\n\t\t// Remove the current keep-alive timer if it exists.\n\t\tthis.clearKeepAliveTimer();\n\n\t\t// Get the current timestamp in milliseconds.\n\t\tconst currentTime = Date.now();\n\n\t\t// Follow up and verify that the message got sent..\n\t\tconst verificationTimer = setTimeout(this.verifySend.bind(this, currentTime), this.socket.timeout) as unknown as number;\n\n\t\t// Store the verification timer locally so that it can be cleared when data has been received.\n\t\tthis.verifications.push(verificationTimer);\n\n\t\t// Set a new keep-alive timer.\n\t\tthis.setupKeepAliveTimer();\n\n\t\t// Write the message to the network socket.\n\t\treturn this.socket.write(message + ElectrumProtocol.statementDelimiter);\n\t}\n\n\t// --- Event managers. --- //\n\n\t/**\n\t * Marks the connection as timed out and schedules reconnection if we have not\n\t * received data within the expected time frame.\n\t */\n\tverifySend(sentTimestamp: number): void\n\t{\n\t\t// If we haven't received any data since we last sent data out..\n\t\tif(Number(this.lastReceivedTimestamp) < sentTimestamp)\n\t\t{\n\t\t\t// If this connection is already disconnected, we do not change anything\n\t\t\tif((this.status === ConnectionStatus.DISCONNECTED) || (this.status === ConnectionStatus.DISCONNECTING))\n\t\t\t{\n\t\t\t\t// debug.warning(`Tried to verify already disconnected connection to '${this.hostIdentifier}'`);\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Remove the current keep-alive timer if it exists.\n\t\t\tthis.clearKeepAliveTimer();\n\n\t\t\t// Write a notification to the logs.\n\t\t\tdebug.network(`Connection to '${this.hostIdentifier}' timed out.`);\n\n\t\t\t// Close the connection to avoid re-use.\n\t\t\t// NOTE: This initiates reconnection routines if the connection has not\n\t\t\t// been marked as intentionally disconnected.\n\t\t\tthis.socket.disconnect();\n\t\t}\n\t}\n\n\t/**\n\t * Updates the connection status when a connection is confirmed.\n\t */\n\tonSocketConnect(): void\n\t{\n\t\t// If a reconnect timer is set, remove it.\n\t\tthis.clearReconnectTimer();\n\n\t\t// Set up the initial timestamp for when we last received data from the server.\n\t\tthis.lastReceivedTimestamp = Date.now();\n\n\t\t// Set up the initial keep-alive timer.\n\t\tthis.setupKeepAliveTimer();\n\n\t\t// Clear all temporary error listeners.\n\t\tthis.socket.removeAllListeners('error');\n\n\t\t// Set up handler for network errors.\n\t\tthis.socket.on('error', this.onSocketError.bind(this));\n\t}\n\n\t/**\n\t * Updates the connection status when a connection is ended.\n\t */\n\tonSocketDisconnect(): void\n\t{\n\t\t// Remove the current keep-alive timer if it exists.\n\t\tthis.clearKeepAliveTimer();\n\n\t\t// If this is a connection we're trying to tear down..\n\t\tif(this.status === ConnectionStatus.DISCONNECTING)\n\t\t{\n\t\t\t// Mark the connection as disconnected.\n\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t// Send a disconnect signal higher up the stack.\n\t\t\tthis.emit('disconnected');\n\n\t\t\t// If a reconnect timer is set, remove it.\n\t\t\tthis.clearReconnectTimer();\n\n\t\t\t// Remove all event listeners\n\t\t\tthis.removeAllListeners();\n\n\t\t\t// Write a log message.\n\t\t\tdebug.network(`Disconnected from '${this.hostIdentifier}'.`);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// If this is for an established connection..\n\t\t\tif(this.status === ConnectionStatus.CONNECTED)\n\t\t\t{\n\t\t\t\t// Write a notification to the logs.\n\t\t\t\tdebug.errors(`Connection with '${this.hostIdentifier}' was closed, trying to reconnect in ${this.options.reconnectAfterMilliSeconds / 1000} seconds.`);\n\t\t\t}\n\t\t\t// If this is a connection that is currently connecting, reconnecting or already disconnected..\n\t\t\telse\n\t\t\t{\n\t\t\t\t// Do nothing\n\n\t\t\t\t// NOTE: This error message is useful during manual debugging of reconnections.\n\t\t\t\t// debug.errors(`Lost connection with reconnecting or already disconnected server '${this.hostIdentifier}'.`);\n\t\t\t}\n\n\t\t\t// Mark the connection as disconnected for now..\n\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\n\n\t\t\t// Send a disconnect signal higher up the stack.\n\t\t\tthis.emit('disconnected');\n\n\t\t\t// If we don't have a pending reconnection timer..\n\t\t\tif(!this.reconnectTimer)\n\t\t\t{\n\t\t\t\t// Attempt to reconnect after one keep-alive duration.\n\t\t\t\tthis.reconnectTimer = setTimeout(this.reconnect.bind(this), this.options.reconnectAfterMilliSeconds) as unknown as number;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Notify administrator of any unexpected errors.\n\t */\n\tonSocketError(error: any | undefined): void\n\t{\n\t\t// Report a generic error if no error information is present.\n\t\t// NOTE: When using WSS, the error event explicitly\n\t\t// only allows to send a \"simple\" event without data.\n\t\t// https://stackoverflow.com/a/18804298\n\t\tif(typeof error === 'undefined')\n\t\t{\n\t\t\t// Do nothing, and instead rely on the socket disconnect event for further information.\n\t\t\treturn;\n\t\t}\n\n\t\t// Log the error, as there is nothing we can do to actually handle it.\n\t\tdebug.errors(`Network error ('${this.hostIdentifier}'): `, error);\n\t}\n}\n","import { RPCParameter } from './rpc-interfaces';\n\n/**\n * Grouping of utilities that simplifies implementation of the Electrum protocol.\n *\n * @ignore\n */\nexport class ElectrumProtocol\n{\n\t/**\n\t * Helper function that builds an Electrum request object.\n\t *\n\t * @param method - method to call.\n\t * @param parameters - method parameters for the call.\n\t * @param requestId - unique string or number referencing this request.\n\t *\n\t * @returns a properly formatted Electrum request string.\n\t */\n\tstatic buildRequestObject(method: string, parameters: RPCParameter[], requestId: string | number): string\n\t{\n\t\t// Return the formatted request object.\n\t\t// NOTE: Electrum either uses JsonRPC strictly or loosely.\n\t\t// If we specify protocol identifier without being 100% compliant, we risk being disconnected/blacklisted.\n\t\t// For this reason, we omit the protocol identifier to avoid issues.\n\t\treturn JSON.stringify({ method: method, params: parameters, id: requestId });\n\t}\n\n\t/**\n\t * Constant used to verify if a provided string is a valid version number.\n\t *\n\t * @returns a regular expression that matches valid version numbers.\n\t */\n\tstatic get versionRegexp(): RegExp\n\t{\n\t\treturn /^\\d+(\\.\\d+)+$/;\n\t}\n\n\t/**\n\t * Constant used to separate statements/messages in a stream of data.\n\t *\n\t * @returns the delimiter used by Electrum to separate statements.\n\t */\n\tstatic get statementDelimiter(): string\n\t{\n\t\treturn '\\n';\n\t}\n}\n","import type { RPCError, RPCParameter, RPCResponse, RPCNotification } from './rpc-interfaces';\nimport type { EventEmitter } from 'eventemitter3';\n\n/**\n * Optional settings that change the default behavior of the network connection.\n */\nexport interface ElectrumNetworkOptions\n{\n\t/** If set to true, numbers that can safely be parsed as integers will be `BigInt` rather than `Number`. */\n\tuseBigInt?: boolean;\n\n\t/** When connected, send a keep-alive Ping message this often. */\n\tsendKeepAliveIntervalInMilliSeconds?: number;\n\n\t/** When disconnected, attempt to reconnect after this amount of time. */\n\treconnectAfterMilliSeconds?: number;\n\n\t/** After every send, verify that we have received data after this amount of time. */\n\tverifyConnectionTimeoutInMilliSeconds?: number;\n\n\t/** Turn off automatic handling of browser visibility, which disconnects when application is not visible to be consistent across browsers. */\n\tdisableBrowserVisibilityHandling?: boolean;\n\n\t/** Turn off automatic handling of browser connectivity. */\n\tdisableBrowserConnectivityHandling?: boolean;\n}\n\n/**\n * List of events emitted by the ElectrumSocket.\n * @event\n * @ignore\n */\nexport interface ElectrumSocketEvents\n{\n\t/**\n\t * Emitted when data has been received over the socket.\n\t * @eventProperty\n\t */\n\t'data': [ string ];\n\n\t/**\n\t * Emitted when a socket connects.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a socket disconnects.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when the socket has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * Abstract socket used when communicating with Electrum servers.\n */\nexport interface ElectrumSocket extends EventEmitter<ElectrumSocketEvents>, ElectrumSocketEvents\n{\n\t/**\n\t * Utility function to provide a human accessible host identifier.\n\t */\n\tget hostIdentifier(): string;\n\n\t/**\n\t * Fully qualified domain name or IP address of the host\n\t */\n\thost: string;\n\n\t/**\n\t * Network port for the host to connect to, defaults to the standard TLS port\n\t */\n\tport: number;\n\n\t/**\n\t * If false, uses an unencrypted connection instead of the default on TLS\n\t */\n\tencrypted: boolean;\n\n\t/**\n\t * If no connection is established after `timeout` ms, the connection is terminated\n\t */\n\ttimeout: number;\n\n\t/**\n\t * Connects to an Electrum server using the socket.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects from the Electrum server from the socket.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Write data to the Electrum server on the socket.\n\t *\n\t * @param data - Data to be written to the socket\n\t * @param callback - Callback function to be called when the write has completed\n\t */\n\twrite(data: Uint8Array | string, callback?: (err?: Error) => void): boolean;\n}\n\n/**\n * @ignore\n */\nexport interface VersionRejected\n{\n\terror: RPCError;\n}\n\n/**\n * @ignore\n */\nexport interface VersionNegotiated\n{\n\tsoftware: string;\n\tprotocol: string;\n}\n\n/**\n * @ignore\n */\nexport type VersionNegotiationResponse = VersionNegotiated | VersionRejected;\n\n/**\n * List of events emitted by the ElectrumConnection.\n * @event\n * @ignore\n */\nexport interface ElectrumConnectionEvents\n{\n\t/**\n\t * Emitted when any data has been received over the network.\n\t * @eventProperty\n\t */\n\t'received': [];\n\n\t/**\n\t * Emitted when a complete electrum message has been received over the network.\n\t * @eventProperty\n\t */\n\t'response': [ RPCResponse ];\n\n\t/**\n\t * Emitted when the connection has completed version negotiation.\n\t * @eventProperty\n\t */\n\t'version': [ VersionNegotiationResponse ];\n\n\t/**\n\t * Emitted when a network connection is initiated.\n\t * @eventProperty\n\t */\n\t'connecting': [];\n\n\t/**\n\t * Emitted when a network connection is successful.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a network disconnection is initiated.\n\t * @eventProperty\n\t */\n\t'disconnecting': [];\n\n\t/**\n\t * Emitted when a network disconnection is successful.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when a network connect attempts to automatically reconnect.\n\t * @eventProperty\n\t */\n\t'reconnecting': [];\n\n\t/**\n\t * Emitted when the network has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * List of events emitted by the ElectrumClient.\n * @event\n * @ignore\n */\nexport interface ElectrumClientEvents\n{\n\t/**\n\t * Emitted when an electrum subscription statement has been received over the network.\n\t * @eventProperty\n\t */\n\t'notification': [ RPCNotification ];\n\n\t/**\n\t * Emitted when a network connection is initiated.\n\t * @eventProperty\n\t */\n\t'connecting': [];\n\n\t/**\n\t * Emitted when a network connection is successful.\n\t * @eventProperty\n\t */\n\t'connected': [];\n\n\t/**\n\t * Emitted when a network disconnection is initiated.\n\t * @eventProperty\n\t */\n\t'disconnecting': [];\n\n\t/**\n\t * Emitted when a network disconnection is successful.\n\t * @eventProperty\n\t */\n\t'disconnected': [];\n\n\t/**\n\t * Emitted when a network connect attempts to automatically reconnect.\n\t * @eventProperty\n\t */\n\t'reconnecting': [];\n\n\t/**\n\t * Emitted when the network has failed in some way.\n\t * @eventProperty\n\t */\n\t'error': [ Error ];\n}\n\n/**\n * A list of possible responses to requests.\n * @ignore\n */\nexport type RequestResponse = RPCParameter | RPCParameter[];\n\n/**\n * Request resolvers are used to process the response of a request. This takes either\n * an error object or any stringified data, while the other parameter is omitted.\n * @ignore\n */\nexport type RequestResolver = (error?: Error, data?: string) => void;\n\n/**\n * Typing for promise resolution.\n * @ignore\n */\nexport type ResolveFunction<T> = (value: T | PromiseLike<T>) => void;\n\n/**\n * Typing for promise rejection.\n * @ignore\n */\nexport type RejectFunction = (reason?: any) => void;\n\n/**\n * @ignore\n */\nexport const isVersionRejected = function(object: any): object is VersionRejected\n{\n\treturn 'error' in object;\n};\n\n/**\n * @ignore\n */\nexport const isVersionNegotiated = function(object: any): object is VersionNegotiated\n{\n\treturn 'software' in object && 'protocol' in object;\n};\n","// Acceptable parameter types for RPC messages\nexport type RPCParameter = string | number | boolean | object | null;\n\n// Acceptable identifier types for RCP messages.\nexport type RCPIdentifier = number | string | null;\n\n// The base type for all RPC messages\nexport interface RPCBase\n{\n\tjsonrpc: string;\n}\n\n// An RPC message that sends a notification requiring no response\nexport interface RPCNotification extends RPCBase\n{\n\tmethod: string;\n\tparams?: RPCParameter[];\n}\n\n// An RPC message that sends a request requiring a response\nexport interface RPCRequest extends RPCBase\n{\n\tid: RCPIdentifier;\n\tmethod: string;\n\tparams?: RPCParameter[];\n}\n\n// An RPC message that returns the response to a successful request\nexport interface RPCStatement extends RPCBase\n{\n\tid: RCPIdentifier;\n\tresult: string;\n}\n\nexport interface RPCError\n{\n\tcode: number;\n\tmessage: string;\n\tdata?: any;\n}\n\n// An RPC message that returns the error to an unsuccessful request\nexport interface RPCErrorResponse extends RPCBase\n{\n\tid: RCPIdentifier;\n\terror: RPCError;\n}\n\n// A response to a request is either a statement (successful) or an error (unsuccessful)\nexport type RPCResponse = RPCErrorResponse | RPCStatement | RPCNotification;\n\n// RPC messages are notifications, requests, or responses\nexport type RPCMessage = RPCNotification | RPCRequest | RPCResponse;\n\n// Requests and responses can also be sent in batches\nexport type RPCResponseBatch = RPCResponse[];\nexport type RPCRequestBatch = RPCRequest[];\n\nexport const isRPCErrorResponse = function(message: RPCBase): message is RPCErrorResponse\n{\n\treturn 'id' in message && 'error' in message;\n};\n\nexport const isRPCStatement = function(message: RPCBase): message is RPCStatement\n{\n\treturn 'id' in message && 'result' in message;\n};\n\nexport const isRPCNotification = function(message: RPCBase): message is RPCNotification\n{\n\treturn !('id' in message) && 'method' in message;\n};\n\nexport const isRPCRequest = function(message: RPCBase): message is RPCRequest\n{\n\treturn 'id' in message && 'method' in message;\n};\n","// Disable indent rule for this file because it is broken (https://github.com/typescript-eslint/typescript-eslint/issues/1824)\n/* eslint-disable @typescript-eslint/indent */\n\n/**\n * Enum that denotes the connection status of an ElectrumConnection.\n * @enum {number}\n * @property {0} DISCONNECTED The connection is disconnected.\n * @property {1} AVAILABLE The connection is connected.\n * @property {2} DISCONNECTING The connection is disconnecting.\n * @property {3} CONNECTING The connection is connecting.\n * @property {4} RECONNECTING The connection is restarting.\n */\nexport enum ConnectionStatus\n{\n\tDISCONNECTED = 0,\n\tCONNECTED = 1,\n\tDISCONNECTING = 2,\n\tCONNECTING = 3,\n\tRECONNECTING = 4,\n}\n","import { ElectrumNetworkOptions } from './interfaces';\n\n// Define number of milliseconds per second for legibility.\nconst MILLI_SECONDS_PER_SECOND = 1000;\n\n/**\n * Configure default options.\n */\nexport const defaultNetworkOptions: ElectrumNetworkOptions =\n{\n\t// By default, all numbers including integers are parsed as regular JavaScript numbers.\n\tuseBigInt: false,\n\n\t// Send a ping message every seconds, to detect network problem as early as possible.\n\tsendKeepAliveIntervalInMilliSeconds: 1 * MILLI_SECONDS_PER_SECOND,\n\n\t// Try to reconnect 5 seconds after unintentional disconnects.\n\treconnectAfterMilliSeconds: 5 * MILLI_SECONDS_PER_SECOND,\n\n\t// Try to detect stale connections 5 seconds after every send.\n\tverifyConnectionTimeoutInMilliSeconds: 5 * MILLI_SECONDS_PER_SECOND,\n\n\t// Automatically manage the connection for a consistent behavior across browsers and devices.\n\tdisableBrowserVisibilityHandling: false,\n\tdisableBrowserConnectivityHandling: false,\n};\n"],"names":[],"version":3,"file":"index.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@electrum-cash/network",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4-development.11641455551",
|
|
4
4
|
"description": "@electrum-cash/network is a lightweight JavaScript library that lets you connect with one or more Electrum servers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"electrum",
|
|
@@ -54,16 +54,16 @@
|
|
|
54
54
|
"@parcel/transformer-typescript-types": "^2.9.2",
|
|
55
55
|
"@types/debug": "^4.1.6",
|
|
56
56
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
57
|
-
"@vitest/coverage-v8": "^2.
|
|
57
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
58
58
|
"cspell": "^8.6.0",
|
|
59
|
-
"del-cli": "^
|
|
59
|
+
"del-cli": "^7.0.0",
|
|
60
60
|
"eslint": "^8.57.1",
|
|
61
61
|
"eslint-plugin-import": "^2.23.4",
|
|
62
62
|
"parcel": "^2.9.2",
|
|
63
63
|
"typedoc": "^0.26.8",
|
|
64
64
|
"typedoc-plugin-coverage": "^3.1.0",
|
|
65
65
|
"typescript": "^5.1.3",
|
|
66
|
-
"vitest": "^2.
|
|
66
|
+
"vitest": "^3.2.4"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@electrum-cash/debug-logs": "^1.0.0",
|