@electrum-cash/network 4.0.0-development.6620959073 → 4.0.0-development.6621103710

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.
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;AEEA,yBAAyB;AACzB,MAAM,8BACN;IACC,QAAS,CAAA,GAAA,YAAU,EAAE;IACrB,QAAS,CAAA,GAAA,YAAU,EAAE;IACrB,SAAS,CAAA,GAAA,YAAU,EAAE;IACrB,SAAS,CAAA,GAAA,YAAU,EAAE;IACrB,MAAS,CAAA,GAAA,YAAU,EAAE;AACtB;AAEA,kBAAkB;AAClB,4BAAM,MAAM,CAAC,KAAK,GAAG;AACrB,4BAAM,MAAM,CAAC,KAAK,GAAG;AACrB,4BAAM,OAAO,CAAC,KAAK,GAAG;AACtB,4BAAM,OAAO,CAAC,KAAK,GAAG;AACtB,4BAAM,IAAI,CAAC,KAAK,GAAG;IAEnB,mBAAmB;AACnB,2CAAe;;;;AElBf;;;;CAIC,GACD,MAAM;IAEL;;;;;;;;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;IAEA,uBAAuB;AACvB,2CAAe;;;;;;;ACZR,MAAM,4CAAoB,SAAS,MAAW;IAEpD,OAAO,WAAW;AACnB;AAEO,MAAM,4CAAsB,SAAS,MAAW;IAEtD,OAAO,cAAc,UAAU,cAAc;AAC9C;;;;;;;AClCO,MAAM,4CACb;IACC,KAAS;QAAE,MAAM;QAAO,QAAQ;IAAyB;IACzD,SAAS;QAAE,MAAM;QAA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,gBAAgB,WAAW,QAAQ,MAAM;YAEzC,yDAAyD;YACzD,IAAI,CAAC,oCAAoC,CAAC;QAC3C;IACD;IAEA;;;;;EAKC,GACD,yBACA;QACC,gDAAgD;QAChD,IAAI,CAAC,IAAI,CAAC;QAEV,4BAA4B;QAC5B,IAAI,MAAM,cAAc,IAAI,CAAC,gBAAgB,CAC7C;YACC,2CAA2C;YAC3C,MAAM,kBAAkB,IAAI,CAAC,gBAAgB,CAAC,WAAW;YAEzD,oFAAoF;YACpF,gBAAgB,IAAI,MAAM;YAE1B,4CAA4C;YAC5C,OAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW;QACzC;IACD;IAEA;;;;EAIC,GACD,MAAM,qBAAqB,gBAAgB,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,uDAAuD;QACvD,IAAG,OAAO,QAAQ,MAAM,CAAC,YAAY,KAAK,aAEzC,oCAAoC;QACpC,IAAI,CAAC,WAAW,GAAG,QAAQ,MAAM,CAAC,YAAY;IAEhD;AACD;IAEA,qBAAqB;AACrB,2CAAe","sources":["source/index.ts","source/electrum-client.ts","source/util.ts","source/electrum-connection.ts","source/electrum-protocol.ts","source/interfaces.ts","source/constants.ts","source/electrum-socket.ts","source/enums.ts","source/rpc-interfaces.ts"],"sourcesContent":["export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './constants';\nexport * from './enums';\n","import debug from './util';\nimport ElectrumConnection from './electrum-connection';\nimport ElectrumProtocol from './electrum-protocol';\nimport { DefaultParameters } from './constants';\nimport { EventEmitter } from 'events';\nimport { ConnectionStatus } from './enums';\nimport { RPCParameter, isRPCNotification, isRPCErrorResponse, RPCNotification, RPCResponse } from './rpc-interfaces';\nimport type { ResolveFunction, RequestResolver, RequestResponse, TransportScheme } from './interfaces';\nimport { Mutex } from 'async-mutex';\n\n/**\n * Triggers when the underlying connection is established.\n *\n * @event ElectrumClient#connected\n */\n\n/**\n * Triggers when the underlying connection is lost.\n *\n * @event ElectrumClient#disconnected\n */\n\n/**\n * Triggers when the remote server sends data that is not a request response.\n *\n * @event ElectrumClient#notification\n */\n\n/**\n * High-level Electrum client that lets applications send requests and subscribe to notification events from a server.\n */\nclass ElectrumClient extends EventEmitter\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 * @note 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 * @note 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// 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 {string} application your application name, used to identify to the electrum host.\n\t * @param {string} version protocol version to use with the host.\n\t * @param {string} host fully qualified domain name or IP number of the host.\n\t * @param {number} port the TCP network port of the host.\n\t * @param {TransportScheme} scheme the transport scheme to use for connection\n\t * @param {number} timeout how long network delays we will wait for before taking action, in milliseconds.\n\t * @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds.\n\t * @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds.\n\t * @param {boolean} useBigInt\t\t\t whether to use bigint for numbers in json response.\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 host: string,\n\t\tpublic port: number = DefaultParameters.PORT,\n\t\tpublic scheme: TransportScheme = DefaultParameters.TRANSPORT_SCHEME,\n\t\tpublic timeout: number = DefaultParameters.TIMEOUT,\n\t\tpublic pingInterval: number = DefaultParameters.PING_INTERVAL,\n\t\tpublic reconnectInterval: number = DefaultParameters.RECONNECT,\n\t\tpublic useBigInt: boolean = DefaultParameters.USE_BIG_INT,\n\t)\n\t{\n\t\t// Initialize the event emitter.\n\t\tsuper();\n\n\t\t// Set up a connection to an electrum server.\n\t\tthis.connection = new ElectrumConnection(application, version, host, port, scheme, timeout, pingInterval, reconnectInterval, useBigInt);\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('statement', this.response.bind(this));\n\n\t\t\t// Hook up resubscription on connection.\n\t\t\tthis.connection.on('connect', this.resubscribeOnConnect.bind(this));\n\n\t\t\t// Relay connect and disconnect events.\n\t\t\tthis.connection.on('connect', this.emit.bind(this, 'connected'));\n\t\t\tthis.connection.on('disconnect', this.onConnectionDisconnect.bind(this));\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 {boolean} force disconnect even if the connection has not been fully established yet.\n\t * @param {boolean} 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\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\tif(!retainSubscriptions)\n\t\t\t{\n\t\t\t\t// Cancel all event listeners.\n\t\t\t\tthis.removeAllListeners();\n\n\t\t\t\t// Remove all subscription data\n\t\t\t\tthis.subscriptionMethods = {};\n\t\t\t}\n\n\t\t\t// For each pending request..\n\t\t\tfor(const index in this.requestResolvers)\n\t\t\t{\n\t\t\t\t// Reject the request.\n\t\t\t\tconst requestResolver = this.requestResolvers[index];\n\t\t\t\trequestResolver(new Error('Manual disconnection'));\n\n\t\t\t\t// Remove the request.\n\t\t\t\tdelete this.requestResolvers[index];\n\t\t\t}\n\n\t\t\t// Disconnect from the remove server.\n\t\t\treturn await this.connection.disconnect(force);\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 * Calls a method on the remote server with the supplied parameters.\n\t *\n\t * @param {string} method name of the method to call.\n\t * @param {...string} 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.connection.host}'.`));\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 as RequestResponse);\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.connection.host}'`);\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 * @note the response for the subscription request is issued as a notification event.\n\t *\n\t * @param {string} method one of the subscribable methods the server supports.\n\t * @param {...string} 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// Construct a notification structure to package the initial result as a notification.\n\t\tconst notification =\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 {string} method a previously subscribed to method.\n\t * @param {...string} 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.connection.host}'.`));\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.connection.hostIdentifier}'.`);\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.connection.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 {RPCNotification | RPCResponse} 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: RPCNotification | 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.connection.host}'`);\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// Throw an internal error, this should not happen.\n\t\t\tthrow(new Error('Internal error: Callback for response not available.'));\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\tonConnectionDisconnect(): void\n\t{\n\t\t// Emit a disconnection signal to any listeners.\n\t\tthis.emit('disconnected');\n\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\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\t// If the message is a response to a features request..\n\t\tif(typeof message.result.genesis_hash !== 'undefined')\n\t\t{\n\t\t\t// ..store the genesis hash locally.\n\t\t\tthis.genesisHash = message.result.genesis_hash;\n\t\t}\n\t}\n}\n\n// Export the client.\nexport default ElectrumClient;\n","import debugLogger from 'debug';\n\n// Create the debug logs.\nconst debug =\n{\n\tclient: debugLogger('electrum-cash:client '),\n\terrors: debugLogger('electrum-cash:error '),\n\twarning: debugLogger('electrum-cash:warning'),\n\tnetwork: debugLogger('electrum-cash:network'),\n\tping: debugLogger('electrum-cash:pulses '),\n};\n\n// Set log colors.\ndebug.client.color = '2';\ndebug.errors.color = '9';\ndebug.warning.color = '13';\ndebug.network.color = '4';\ndebug.ping.color = '8';\n\n// Export the logs.\nexport default debug;\n","import debug from './util';\nimport ElectrumProtocol from './electrum-protocol';\nimport { ResolveFunction, RejectFunction, VersionRejected, VersionNegotiated, isVersionRejected, TransportScheme } from './interfaces';\nimport { DefaultParameters, ElectrumTransport } from './constants';\nimport { EventEmitter } from 'events';\nimport { ElectrumTcpSocket, ElectrumWebSocket } from './electrum-socket';\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 */\nclass ElectrumConnection extends EventEmitter\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: ElectrumTcpSocket | ElectrumWebSocket;\n\n\t// Declare timers for keep-alive pings and reconnection\n\tprivate timers: {\n\t\t// eslint-disable-next-line no-undef\n\t\tkeepAlive?: number;\n\t\t// eslint-disable-next-line no-undef\n\t\treconnect?: number;\n\t} = {};\n\n\t// Initialize an empty array of connection verification timers.\n\t// eslint-disable-next-line no-undef\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 {string} application your application name, used to identify to the electrum host.\n\t * @param {string} version protocol version to use with the host.\n\t * @param {string} host fully qualified domain name or IP number of the host.\n\t * @param {number} port the network port of the host.\n\t * @param {TransportScheme} scheme the transport scheme to use for connection\n\t * @param {number} timeout how long network delays we will wait for before taking action, in milliseconds.\n\t * @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds.\n\t * @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds.\n\t * @param {boolean} useBigInt\t \t\t whether to use bigint for numbers in json response.\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 host: string,\n\t\tpublic port: number = DefaultParameters.PORT,\n\t\tpublic scheme: TransportScheme = DefaultParameters.TRANSPORT_SCHEME,\n\t\tpublic timeout: number = DefaultParameters.TIMEOUT,\n\t\tpublic pingInterval: number = DefaultParameters.PING_INTERVAL,\n\t\tpublic reconnectInterval: number = DefaultParameters.RECONNECT,\n\t\tpublic useBigInt: boolean = DefaultParameters.USE_BIG_INT,\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// Create an initial network socket.\n\t\tthis.createSocket();\n\n\t\t// Handle visibility changes when run in a browser environment.\n\t\tif(typeof document !== 'undefined')\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.\n\t\tif(typeof window !== 'undefined')\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/**\n\t * Returns a string for the host identifier for usage in debug messages.\n\t */\n\tget hostIdentifier(): string\n\t{\n\t\treturn `${this.host}:${this.port}`;\n\t}\n\n\t/**\n\t * Create and configures a fresh socket and attaches all relevant listeners.\n\t */\n\tcreateSocket(): void\n\t{\n\t\tif(this.scheme === ElectrumTransport.TCP.Scheme || this.scheme === ElectrumTransport.TCP_TLS.Scheme)\n\t\t{\n\t\t\t// Initialize a new ElectrumTcpSocket\n\t\t\tthis.socket = new ElectrumTcpSocket();\n\t\t}\n\t\telse if(this.scheme === ElectrumTransport.WS.Scheme || this.scheme === ElectrumTransport.WSS.Scheme)\n\t\t{\n\t\t\t// Initialize a new ElectrumWebSocket\n\t\t\tthis.socket = new ElectrumWebSocket();\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Throw an error if an incorrect transport is specified\n\t\t\tthrow(new Error(`Provided transport (${this.scheme}) is not a valid ElectrumTransport`));\n\t\t}\n\n\t\t// Set up handlers for connection and disconnection.\n\t\tthis.socket.on('connect', this.onSocketConnect.bind(this));\n\t\tthis.socket.on('disconnect', 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\t}\n\n\t/**\n\t * Shuts down and destroys the current socket.\n\t */\n\tdestroySocket(): void\n\t{\n\t\t// Close the socket connection and destroy the socket.\n\t\tthis.socket.disconnect();\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 {string} 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: any = parse(currentStatementList, null, this.useBigInt ? parseNumberAndBigInt : parseFloat);\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 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(currentStatement.error)\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('statement', 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// 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// 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: VersionRejected | VersionNegotiated): 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('connect');\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('connect', 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(this.host, this.port, this.scheme, this.timeout);\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// Destroy and recreate the socket to get a clean slate.\n\t\tthis.destroySocket();\n\t\tthis.createSocket();\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.timers.reconnect)\n\t\t{\n\t\t\tclearTimeout(this.timers.reconnect);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.timers.reconnect = 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.timers.keepAlive)\n\t\t{\n\t\t\tclearTimeout(this.timers.keepAlive);\n\t\t}\n\n\t\t// Reset the timer reference.\n\t\tthis.timers.keepAlive = 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.timers.keepAlive)\n\t\t{\n\t\t\t// Set a new keep-alive timer.\n\t\t\tthis.timers.keepAlive = setTimeout(this.ping.bind(this), this.pingInterval) 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 {boolean} force disconnect even if the connection has not been fully established yet.\n\t * @param {boolean} 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// 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('disconnect', () => resolve(true));\n\n\t\t\t// Close the connection and destroy the socket.\n\t\t\tthis.destroySocket();\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 * TODO: Use\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 navigator === 'undefined')\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Do nothing if we might still be online.\n\t\t// NOTE: we check for not-false here since true does not mean that we are connected to the internet,\n\t\t// but rather that the browser believes there is an active network connection of any type.\n\t\tif(window.navigator.onLine !== false)\n\t\t{\n\t\t\treturn;\n\t\t}\n\n\t\t// Disconnect without signalling intent, to trigger automatic recovery routines.\n\t\tthis.disconnect(false, false);\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 isIntended = false;\n\n\t\t\tthis.disconnect(forceDisconnect, isIntended);\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 {string} 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.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// Send a disconnect signal higher up the stack.\n\t\tthis.emit('disconnect');\n\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// 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// Mark the connection as disconnected.\n\t\t\tthis.status = ConnectionStatus.DISCONNECTED;\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.reconnectInterval / 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// If we don't have a pending reconnection timer..\n\t\t\tif(!this.timers.reconnect)\n\t\t\t{\n\t\t\t\t// Attempt to reconnect after one keep-alive duration.\n\t\t\t\tthis.timers.reconnect = setTimeout(this.reconnect.bind(this), this.reconnectInterval) 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// If the DNS lookup failed.\n\t\tif(error.code === 'EAI_AGAIN')\n\t\t{\n\t\t\tdebug.errors(`Failed to look up DNS records for '${this.host}'.`);\n\n\t\t\treturn;\n\t\t}\n\n\t\t// If the connection timed out..\n\t\tif(error.code === 'ETIMEDOUT')\n\t\t{\n\t\t\t// Log the provided timeout message.\n\t\t\tdebug.errors(error.message);\n\n\t\t\treturn;\n\t\t}\n\n\t\t// Log unknown error\n\t\tdebug.errors(`Unknown network error ('${this.hostIdentifier}'): `, error);\n\t}\n}\n\n// Export the connection.\nexport default ElectrumConnection;\n","import { RPCParameter } from './rpc-interfaces';\n\n/**\n * Grouping of utilities that simplifies implementation of the Electrum protocol.\n *\n * @ignore\n */\nclass ElectrumProtocol\n{\n\t/**\n\t * Helper function that builds an Electrum request object.\n\t *\n\t * @param {string} method method to call.\n\t * @param {array} parameters method parameters for the call.\n\t * @param {string} 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\n// export the protocol.\nexport default ElectrumProtocol;\n","import type { ClientState } from './enums';\nimport type ElectrumClient from './electrum-client';\nimport type { RPCError } from './rpc-interfaces';\n\nexport interface ClientConfig\n{\n\t// Availability of the client's connection\n\tstate: ClientState;\n\n\t// The client's connection\n\tconnection: ElectrumClient;\n}\n\n/**\n * A list of possible responses to requests.\n */\nexport type RequestResponse = object | string | number | boolean | null | RequestResponse[];\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.\nexport type RequestResolver = (error?: Error, data?: string) => void;\n\n// Promise types\nexport type ResolveFunction<T> = (value: T | PromiseLike<T>) => void;\nexport type RejectFunction = (reason?: any) => void;\n\nexport interface VersionRejected\n{\n\terror: RPCError;\n}\n\nexport interface VersionNegotiated\n{\n\tsoftware: string;\n\tprotocol: string;\n}\n\nexport const isVersionRejected = function(object: any): object is VersionRejected\n{\n\treturn 'error' in object;\n};\n\nexport const isVersionNegotiated = function(object: any): object is VersionNegotiated\n{\n\treturn 'software' in object && 'protocol' in object;\n};\n\n/**\n * Possible Transport Schemes for communication with the Electrum server\n */\nexport type TransportScheme = 'tcp' | 'tcp_tls' | 'ws' | 'wss';\n\n// Connection options used with TLS connections.\nexport interface ConnectionOptions\n{\n\trejectUnauthorized?: boolean;\n\tserverName?: string;\n}\n","import { TransportScheme } from './interfaces';\n\n/**\n * Object containing the commonly used ports and schemes for specific Transports.\n * @example const electrum = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash', Transport.WSS.Port, Transport.WSS.Scheme);\n *\n * @property {object} TCP Port and Scheme to use unencrypted TCP sockets.\n * @property {object} TCP_TLS Port and Scheme to use TLS-encrypted TCP sockets.\n * @property {object} WS Port and Scheme to use unencrypted WebSockets.\n * @property {object} WSS Port and Scheme to use TLS-encrypted WebSockets.\n */\nexport const ElectrumTransport =\n{\n\tTCP: { Port: 50001, Scheme: 'tcp' as TransportScheme },\n\tTCP_TLS: { Port: 50002, Scheme: 'tcp_tls' as TransportScheme },\n\tWS: { Port: 50003, Scheme: 'ws' as TransportScheme },\n\tWSS: { Port: 50004, Scheme: 'wss' as TransportScheme },\n};\n\nexport const DefaultParameters =\n{\n\t// Port number for TCP TLS connections\n\tPORT: ElectrumTransport.TCP_TLS.Port,\n\n\t// Transport to connect to the Electrum server\n\tTRANSPORT_SCHEME: ElectrumTransport.TCP_TLS.Scheme,\n\n\t// How long to wait before attempting to reconnect, in milliseconds.\n\tRECONNECT: 5 * 1000,\n\n\t// How long to wait for network operations before following up, in milliseconds.\n\tTIMEOUT: 30 * 1000,\n\n\t// Time between ping messages, in milliseconds. Pinging keeps the connection alive.\n\t// The reason for pinging this frequently is to detect connection problems early.\n\tPING_INTERVAL: 1 * 1000,\n\n\t// If we use BigInt for numbers in json when parsing and returning json response from the server.\n\tUSE_BIG_INT: false,\n};\n","import * as tls from 'tls';\nimport * as net from 'net';\nimport { WebSocket } from '@monsterbitar/isomorphic-ws';\nimport type { MessageEvent, ErrorEvent } from '@monsterbitar/isomorphic-ws';\nimport { EventEmitter } from 'events';\nimport debug from './util';\nimport { ElectrumTransport } from './constants';\nimport { TransportScheme, ConnectionOptions } from './interfaces';\n\nexport class ElectrumTcpSocket extends EventEmitter\n{\n\t// Declare an empty TCP socket.\n\tprivate tcpSocket: net.Socket;\n\n\t// Declare timers for keep-alive pings and reconnection\n\tprivate timers: {\n\t\t// eslint-disable-next-line no-undef\n\t\tretryConnection?: number;\n\t\t// eslint-disable-next-line no-undef\n\t\tdisconnect?: number;\n\t} = {};\n\n\t// Initialize boolean that indicates whether the onConnect function has run (initialize to false).\n\tprivate onConnectHasRun = false;\n\n\t// Initialize event forwarding functions.\n\tprivate eventForwarders =\n\t{\n\t\tdisconnect: () => this.emit('disconnect'),\n\t\ttcpData: (data: string) => this.emit('data', data),\n\t\ttcpError: (err: Error) => this.emit('error', err),\n\t};\n\n\t/**\n\t * Connect to host:port using the specified transport\n\t *\n\t * @param {string} host Fully qualified domain name or IP address of the host\n\t * @param {number} port Network port for the host to connect to\n\t * @param {TransportScheme} scheme Transport scheme to use\n\t * @param {number} timeout If no connection is established after `timeout` ms, the connection is terminated\n\t *\n\t * @throws {Error} if an incorrect transport scheme is specified\n\t */\n\tconnect(host: string, port: number, scheme: TransportScheme, timeout: number): void\n\t{\n\t\t// Check that no existing socket exists before initiating a new connection.\n\t\tif(this.tcpSocket)\n\t\t{\n\t\t\tthrow(new Error('Cannot initiate a new socket connection when an existing connection exists'));\n\t\t}\n\n\t\t// Set a timer to force disconnect after `timeout` seconds\n\t\tthis.timers.disconnect = setTimeout(() => this.disconnectOnTimeout(host, port, timeout), timeout) as unknown as number;\n\n\t\t// Remove the timer if a connection is successfully established\n\t\tthis.once('connect', this.clearDisconnectTimerOnTimeout);\n\n\t\t// Define how to refer to the connection scheme in debug output.\n\t\tconst socketTypes =\n\t\t{\n\t\t\t[ElectrumTransport.TCP.Scheme]: 'a TCP Socket',\n\t\t\t[ElectrumTransport.TCP_TLS.Scheme]: 'an encrypted TCP socket',\n\t\t};\n\n\t\t// Log that we are trying to establish a connection.\n\t\tdebug.network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);\n\n\t\tif(scheme !== ElectrumTransport.TCP.Scheme && scheme !== ElectrumTransport.TCP_TLS.Scheme)\n\t\t{\n\t\t\t// Throw an error if an incorrect transport is specified\n\t\t\tthrow(new Error('Incorrect transport specified'));\n\t\t}\n\n\t\tif(scheme === ElectrumTransport.TCP_TLS.Scheme)\n\t\t{\n\t\t\t// Initialize connection options.\n\t\t\tconst connectionOptions: ConnectionOptions = { rejectUnauthorized: false };\n\n\t\t\t// If the hostname is not an IP address..\n\t\t\tif(!net.isIP(host))\n\t\t\t{\n\t\t\t\t// Set the servername option which enables support for SNI.\n\t\t\t\t// NOTE: SNI enables a server that hosts multiple domains to provide the appropriate TLS certificate.\n\t\t\t\tconnectionOptions.serverName = host;\n\t\t\t}\n\n\t\t\t// Initialize the socket (allowing self-signed certificates).\n\t\t\tthis.tcpSocket = tls.connect(port, host, connectionOptions);\n\n\t\t\t// Add a 'secureConnect' listener that checks the authorization status of\n\t\t\t// the socket, and logs a warning when it uses a self signed certificate.\n\t\t\tthis.tcpSocket.once('secureConnect', () =>\n\t\t\t{\n\t\t\t\t// Cannot happen, since this event callback *only* exists on TLSSocket\n\t\t\t\tif(!(this.tcpSocket instanceof tls.TLSSocket)) return;\n\n\t\t\t\t// Force cast authorizationError from Error to string (through unknown)\n\t\t\t\t// because it is incorrectly typed as an Error\n\t\t\t\tconst authorizationError = (this.tcpSocket.authorizationError as unknown) as string;\n\t\t\t\tif(authorizationError === 'DEPTH_ZERO_SELF_SIGNED_CERT')\n\t\t\t\t{\n\t\t\t\t\tdebug.warning(`Connection to ${host}:${port} uses a self-signed certificate`);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// Trigger successful connection events.\n\t\t\tthis.tcpSocket.on('secureConnect', this.onConnect.bind(this, socketTypes[scheme], host, port));\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Initialize the socket.\n\t\t\tthis.tcpSocket = net.connect({ host, port });\n\n\t\t\t// Trigger successful connection events.\n\t\t\tthis.tcpSocket.on('connect', this.onConnect.bind(this, socketTypes[scheme], host, port));\n\t\t}\n\n\t\t// Configure encoding.\n\t\tthis.tcpSocket.setEncoding('utf8');\n\n\t\t// Enable persistent connections.\n\t\t// NOTE: This will send a non-data message 0.25 second after last activity.\n\t\t// After 10 consecutive such messages with no response, the connection will be cut.\n\t\tthis.tcpSocket.setKeepAlive(true, 250);\n\n\t\t// Disable buffering of outgoing data.\n\t\tthis.tcpSocket.setNoDelay(true);\n\n\t\t// Forward the encountered errors.\n\t\tthis.tcpSocket.on('error', this.eventForwarders.tcpError);\n\t}\n\n\t/**\n\t * Sets up forwarding of events related to the connection.\n\t *\n\t * @param {string} connectionType Name of the connection/transport type, used for logging.\n\t * @param {string} host Fully qualified domain name or IP address of the host\n\t * @param {number} port Network port for the host to connect to\n\t */\n\tonConnect(connectionType: string, host: string, port: number): void\n\t{\n\t\t// If the onConnect function has already run, do not execute it again.\n\t\tif(this.onConnectHasRun) return;\n\n\t\t// Log that the connection has been established.\n\t\tdebug.network(`Established ${connectionType} connection with '${host}:${port}'.`);\n\n\t\t// Forward the socket events\n\t\tthis.tcpSocket.addListener('close', this.eventForwarders.disconnect);\n\t\tthis.tcpSocket.addListener('data', this.eventForwarders.tcpData);\n\n\t\t// Indicate that the onConnect function has run.\n\t\tthis.onConnectHasRun = true;\n\n\t\t// Emit the connect event.\n\t\tthis.emit('connect');\n\t}\n\n\t/**\n\t * Clears the disconnect timer if it is still active.\n\t */\n\tprivate clearDisconnectTimerOnTimeout(): void\n\t{\n\t\t// Clear the retry timer if it is still active.\n\t\tif(this.timers.disconnect)\n\t\t{\n\t\t\tclearTimeout(this.timers.disconnect);\n\t\t}\n\t}\n\n\t/**\n\t * Forcibly terminate the connection.\n\t *\n\t * @throws {Error} if no connection was found\n\t */\n\tdisconnect(): void\n\t{\n\t\t// Clear the disconnect timer so that the socket does not try to disconnect again later.\n\t\tthis.clearDisconnectTimerOnTimeout();\n\n\t\tif(this.tcpSocket)\n\t\t{\n\t\t\t// Remove all event forwarders.\n\t\t\tthis.tcpSocket.removeListener('close', this.eventForwarders.disconnect);\n\t\t\tthis.tcpSocket.removeListener('data', this.eventForwarders.tcpData);\n\t\t\tthis.tcpSocket.removeListener('error', this.eventForwarders.tcpError);\n\n\t\t\t// Terminate the connection.\n\t\t\tthis.tcpSocket.destroy();\n\n\t\t\t// Remove the stored socket.\n\t\t\tthis.tcpSocket = undefined;\n\t\t}\n\n\t\t// Indicate that the onConnect function has not run and it has to be run again.\n\t\tthis.onConnectHasRun = false;\n\n\t\t// Emit a disconnect event\n\t\tthis.emit('disconnect');\n\t}\n\n\t/**\n\t * Write data to the socket\n\t *\n\t * @param {Uint8Array | string} data Data to be written to the socket\n\t * @param {function} callback Callback function to be called when the write has completed\n\t *\n\t * @throws {Error} if no connection was found\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\twrite(data: Uint8Array | string, callback?: (err?: Error) => void): boolean\n\t{\n\t\t// Throw an error if no active connection is found\n\t\tif(!this.tcpSocket)\n\t\t{\n\t\t\tthrow(new Error('Cannot write to socket when there is no active connection'));\n\t\t}\n\n\t\t// Write data to the TLS Socket and return the status indicating\n\t\t// whether the full message was flushed to the socket\n\t\treturn this.tcpSocket.write(data, callback);\n\t}\n\n\t/**\n\t * Force a disconnection if no connection is established after `timeout` milliseconds.\n\t *\n\t * @param {string} host Host of the connection that timed out\n\t * @param {number} port Port of the connection that timed out\n\t * @param {number} timeout Elapsed milliseconds\n\t */\n\tdisconnectOnTimeout(host: string, port: number, timeout: number): void\n\t{\n\t\t// Remove the connect listener.\n\t\tthis.removeListener('connect', this.clearDisconnectTimerOnTimeout);\n\n\t\t// Create a new timeout error.\n\t\tconst timeoutError = { code: 'ETIMEDOUT', message: `Connection to '${host}:${port}' timed out after ${timeout} milliseconds` };\n\n\t\t// Emit an error event so that connect is rejected upstream.\n\t\tthis.emit('error', timeoutError);\n\n\t\t// Forcibly disconnect to clean up the connection on timeout\n\t\tthis.disconnect();\n\t}\n}\n\n/**\n * Isomorphic Socket interface supporting TCP sockets and WebSockets (Node and browser).\n * The interface is a subset of the TLSSocket interface with some slight modifications.\n * It can be expanded when more socket functionality is needed in the rest of the\n * electrum-cash code. Changes from the TLSSocket interface (besides it being a subset):\n * - Event 'close' -> 'disconnect'\n * - New function socket.disconnect()\n *\n * @ignore\n */\nexport class ElectrumWebSocket extends EventEmitter\n{\n\t// Declare an empty WebSocket.\n\tprivate webSocket: WebSocket;\n\n\t// Declare timers for keep-alive pings and reconnection\n\tprivate timers: {\n\t\t// eslint-disable-next-line no-undef\n\t\tretryConnection?: number;\n\t\t// eslint-disable-next-line no-undef\n\t\tdisconnect?: number;\n\t} = {};\n\n\t// Initialize boolean that indicates whether the onConnect function has run (initialize to false).\n\tprivate onConnectHasRun = false;\n\n\t// Initialize event forwarding functions.\n\tprivate eventForwarders =\n\t{\n\t\tdisconnect: () => this.emit('disconnect'),\n\t\twsData: (event: MessageEvent) => this.emit('data', `${event.data}\\n`),\n\t\twsError: (event: ErrorEvent) => this.emit('error', event.error),\n\t};\n\n\t/**\n\t * Connect to host:port using the specified transport\n\t *\n\t * @param {string} host Fully qualified domain name or IP address of the host\n\t * @param {number} port Network port for the host to connect to\n\t * @param {TransportScheme} scheme Transport scheme to use\n\t * @param {number} timeout If no connection is established after `timeout` ms, the connection is terminated\n\t *\n\t * @throws {Error} if an incorrect transport scheme is specified\n\t */\n\tconnect(host: string, port: number, scheme: TransportScheme, timeout: number): void\n\t{\n\t\t// Check that no existing socket exists before initiating a new connection.\n\t\tif(this.webSocket)\n\t\t{\n\t\t\tthrow(new Error('Cannot initiate a new socket connection when an existing connection exists'));\n\t\t}\n\n\t\t// Set a timer to force disconnect after `timeout` seconds\n\t\tthis.timers.disconnect = setTimeout(() => this.disconnectOnTimeout(host, port, timeout), timeout) as unknown as number;\n\n\t\t// Remove the timer if a connection is successfully established\n\t\tthis.once('connect', this.clearDisconnectTimerOnTimeout);\n\n\t\t// Define how to refer to the connection scheme in debug output.\n\t\tconst socketTypes =\n\t\t{\n\t\t\t[ElectrumTransport.WS.Scheme]: 'a WebSocket',\n\t\t\t[ElectrumTransport.WSS.Scheme]: 'an encrypted WebSocket',\n\t\t};\n\n\t\t// Log that we are trying to establish a connection.\n\t\tdebug.network(`Initiating ${socketTypes[scheme]} connection to '${host}:${port}'.`);\n\n\t\tif(scheme !== ElectrumTransport.WS.Scheme && scheme !== ElectrumTransport.WSS.Scheme)\n\t\t{\n\t\t\t// Throw an error if an incorrect transport is specified\n\t\t\tthrow(new Error('Incorrect transport specified'));\n\t\t}\n\n\t\tif(scheme === ElectrumTransport.WSS.Scheme)\n\t\t{\n\t\t\t// Initialize this.webSocket (rejecting self-signed certificates).\n\t\t\t// We reject self-signed certificates to match functionality of browsers.\n\t\t\tthis.webSocket = new WebSocket(`wss://${host}:${port}`);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// Initialize this.webSocket.\n\t\t\tthis.webSocket = new WebSocket(`ws://${host}:${port}`);\n\t\t}\n\n\t\t// Trigger successful connection events.\n\t\tthis.webSocket.addEventListener('open', this.onConnect.bind(this, socketTypes[scheme], host, port));\n\n\t\t// Forward the encountered errors.\n\t\tthis.webSocket.addEventListener('error', this.eventForwarders.wsError);\n\t}\n\n\t/**\n\t * Sets up forwarding of events related to the connection.\n\t *\n\t * @param {string} connectionType Name of the connection/transport type, used for logging.\n\t * @param {string} host Fully qualified domain name or IP address of the host\n\t * @param {number} port Network port for the host to connect to\n\t */\n\tonConnect(connectionType: string, host: string, port: number): void\n\t{\n\t\t// If the onConnect function has already run, do not execute it again.\n\t\tif(this.onConnectHasRun) return;\n\n\t\t// Log that the connection has been established.\n\t\tdebug.network(`Established ${connectionType} connection with '${host}:${port}'.`);\n\n\t\t// Forward the socket events\n\t\tthis.webSocket.addEventListener('close', this.eventForwarders.disconnect);\n\t\tthis.webSocket.addEventListener('message', this.eventForwarders.wsData);\n\n\t\t// Indicate that the onConnect function has run.\n\t\tthis.onConnectHasRun = true;\n\n\t\t// Emit the connect event.\n\t\tthis.emit('connect');\n\t}\n\n\t/**\n\t * Clears the disconnect timer if it is still active.\n\t */\n\tprivate clearDisconnectTimerOnTimeout(): void\n\t{\n\t\t// Clear the retry timer if it is still active.\n\t\tif(this.timers.disconnect)\n\t\t{\n\t\t\tclearTimeout(this.timers.disconnect);\n\t\t}\n\t}\n\n\t/**\n\t * Forcibly terminate the connection.\n\t *\n\t * @throws {Error} if no connection was found\n\t */\n\tdisconnect(): void\n\t{\n\t\t// Clear the disconnect timer so that the socket does not try to disconnect again later.\n\t\tthis.clearDisconnectTimerOnTimeout();\n\n\t\ttry\n\t\t{\n\t\t\t// Remove all event forwarders.\n\t\t\tthis.webSocket.removeEventListener('close', this.eventForwarders.disconnect);\n\t\t\tthis.webSocket.removeEventListener('message', this.eventForwarders.wsData);\n\t\t\tthis.webSocket.removeEventListener('error', this.eventForwarders.wsError);\n\n\t\t\t// Gracefully terminate the connection.\n\t\t\tthis.webSocket.close();\n\t\t}\n\t\tcatch(ignored)\n\t\t{\n\t\t\t// close() will throw an error if the connection has not been established yet.\n\t\t\t// We ignore this error, since no similar error gets thrown in the TLS Socket.\n\t\t}\n\t\tfinally\n\t\t{\n\t\t\t// Remove the stored socket regardless of any thrown errors.\n\t\t\tthis.webSocket = undefined;\n\t\t}\n\n\t\t// Indicate that the onConnect function has not run and it has to be run again.\n\t\tthis.onConnectHasRun = false;\n\n\t\t// Emit a disconnect event\n\t\tthis.emit('disconnect');\n\t}\n\n\t/**\n\t * Write data to the socket\n\t *\n\t * @param {Uint8Array | string} data Data to be written to the socket\n\t * @param {function} callback Callback function to be called when the write has completed\n\t *\n\t * @throws {Error} if no connection was found\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\twrite(data: Uint8Array | string, callback?: (err?: Error) => void): boolean\n\t{\n\t\t// Throw an error if no active connection is found\n\t\tif(!this.webSocket)\n\t\t{\n\t\t\tthrow(new Error('Cannot write to socket when there is no active connection'));\n\t\t}\n\n\t\t// Write data to the WebSocket\n\t\tthis.webSocket.send(data, callback);\n\n\t\t// WebSockets always fit everything in a single request, so we return true\n\t\treturn true;\n\t}\n\n\t/**\n\t * Force a disconnection if no connection is established after `timeout` milliseconds.\n\t *\n\t * @param {string} host Host of the connection that timed out\n\t * @param {number} port Port of the connection that timed out\n\t * @param {number} timeout Elapsed milliseconds\n\t */\n\tdisconnectOnTimeout(host: string, port: number, timeout: number): void\n\t{\n\t\t// Remove the connect listener.\n\t\tthis.removeListener('connect', this.clearDisconnectTimerOnTimeout);\n\n\t\t// Create a new timeout error.\n\t\tconst timeoutError = { code: 'ETIMEDOUT', message: `Connection to '${host}:${port}' timed out after ${timeout} milliseconds` };\n\n\t\t// Emit an error event so that connect is rejected upstream.\n\t\tthis.emit('error', timeoutError);\n\n\t\t// Forcibly disconnect to clean up the connection on timeout\n\t\tthis.disconnect();\n\t}\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 availability of an ElectrumClient.\n * @enum {number}\n * @property {0} UNAVAILABLE The client is currently not available.\n * @property {1} AVAILABLE The client is available for use.\n */\nexport enum ClientState\n{\n\tUNAVAILABLE = 0,\n\tAVAILABLE = 1,\n}\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","// Acceptable parameter types for RPC messages\nexport type RPCParameter = string | number | boolean | 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: number | null;\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: number | null;\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: number | null;\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;\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"],"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.0.0-development.6620959073",
3
+ "version": "4.0.0-development.6621103710",
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",
@@ -26,6 +26,7 @@
26
26
  "license": "MIT",
27
27
  "source": "source/index.ts",
28
28
  "type": "module",
29
+ "module": "./dist/index.mjs",
29
30
  "types": "./dist/index.d.ts",
30
31
  "exports": {
31
32
  "types": "./dist/index.d.ts",