electrum-cash
Advanced tools
Comparing version 2.0.10 to 3.0.0
@@ -1,8 +0,27 @@ | ||
/// <reference types="node" /> | ||
/// <reference types="ws" /> | ||
import { EventEmitter } from 'events'; | ||
import net from 'net'; | ||
import WebSocket, { MessageEvent, ErrorEvent } from 'isomorphic-ws'; | ||
import { Mutex } from 'async-mutex'; | ||
import net from "net"; | ||
import WebSocket, { MessageEvent, ErrorEvent } from "isomorphic-ws"; | ||
import { EventEmitter } from "events"; | ||
import { Mutex } from "async-mutex"; | ||
type RPCParameter = string | number | boolean | null; | ||
interface RPCBase { | ||
jsonrpc: string; | ||
} | ||
interface RPCNotification extends RPCBase { | ||
method: string; | ||
params?: RPCParameter[]; | ||
} | ||
interface RPCStatement extends RPCBase { | ||
id: number | null; | ||
result: string; | ||
} | ||
interface RPCError { | ||
code: number; | ||
message: string; | ||
data?: any; | ||
} | ||
interface RPCErrorResponse extends RPCBase { | ||
id: number | null; | ||
error: RPCError; | ||
} | ||
type RPCResponse = RPCErrorResponse | RPCStatement; | ||
/** | ||
@@ -14,3 +33,3 @@ * Enum that denotes the ordering to use in an ElectrumCluster. | ||
*/ | ||
declare enum ClusterOrder { | ||
export enum ClusterOrder { | ||
RANDOM = 0, | ||
@@ -24,3 +43,3 @@ PRIORITY = 1 | ||
*/ | ||
declare enum ClusterDistribution { | ||
export enum ClusterDistribution { | ||
ALL = 0 | ||
@@ -35,3 +54,3 @@ } | ||
*/ | ||
declare enum ClusterStatus { | ||
export enum ClusterStatus { | ||
DISABLED = 0, | ||
@@ -47,3 +66,3 @@ DEGRADED = 1, | ||
*/ | ||
declare enum ClientState { | ||
export enum ClientState { | ||
UNAVAILABLE = 0, | ||
@@ -61,3 +80,3 @@ AVAILABLE = 1 | ||
*/ | ||
declare enum ConnectionStatus { | ||
export enum ConnectionStatus { | ||
DISCONNECTED = 0, | ||
@@ -69,32 +88,3 @@ CONNECTED = 1, | ||
} | ||
declare type RPCParameter = string | number | boolean | null; | ||
interface RPCBase { | ||
jsonrpc: string; | ||
} | ||
interface RPCNotification extends RPCBase { | ||
method: string; | ||
params?: RPCParameter[]; | ||
} | ||
interface RPCStatement extends RPCBase { | ||
id: number | null; | ||
result: string; | ||
} | ||
interface RPCError { | ||
code: number; | ||
message: string; | ||
data?: any; | ||
} | ||
interface RPCErrorResponse extends RPCBase { | ||
id: number | null; | ||
error: RPCError; | ||
} | ||
declare type RPCResponse = RPCErrorResponse | RPCStatement; | ||
interface ClusterStrategy { | ||
distribution: number; | ||
confidence: number; | ||
order: ClusterOrder; | ||
} | ||
interface ClientConfig { | ||
export interface ClientConfig { | ||
state: ClientState; | ||
@@ -106,30 +96,61 @@ connection: ElectrumClient; | ||
*/ | ||
declare type RequestResponse = object | string | number | boolean | null | RequestResponse[]; | ||
interface SubscriptionTracker { | ||
method: string; | ||
payload: string; | ||
} | ||
declare type SubscribeCallback = (errorOrData: Error | RequestResponse) => void; | ||
declare type RequestResolver = (error?: Error, data?: string) => void; | ||
declare type ResolveFunction<T> = (value: T | PromiseLike<T>) => void; | ||
declare type RejectFunction = (reason?: any) => void; | ||
interface VersionRejected { | ||
export type RequestResponse = object | string | number | boolean | null | RequestResponse[]; | ||
export type RequestResolver = (error?: Error, data?: string) => void; | ||
export type ResolveFunction<T> = (value: T | PromiseLike<T>) => void; | ||
export type RejectFunction = (reason?: any) => void; | ||
export interface VersionRejected { | ||
error: RPCError; | ||
} | ||
interface VersionNegotiated { | ||
export interface VersionNegotiated { | ||
software: string; | ||
protocol: string; | ||
} | ||
declare const isVersionRejected: (object: any) => object is VersionRejected; | ||
declare const isVersionNegotiated: (object: any) => object is VersionNegotiated; | ||
export const isVersionRejected: (object: any) => object is VersionRejected; | ||
export const isVersionNegotiated: (object: any) => object is VersionNegotiated; | ||
/** | ||
* Possible Transport Schemes for communication with the Electrum server | ||
*/ | ||
declare type TransportScheme = 'tcp' | 'tcp_tls' | 'ws' | 'wss'; | ||
interface ConnectionOptions { | ||
export type TransportScheme = 'tcp' | 'tcp_tls' | 'ws' | 'wss'; | ||
export interface ConnectionOptions { | ||
rejectUnauthorized?: boolean; | ||
serverName?: string; | ||
} | ||
/** | ||
* Object containing the commonly used ports and schemes for specific Transports. | ||
* @example const electrum = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash', Transport.WSS.Port, Transport.WSS.Scheme); | ||
* | ||
* @property {object} TCP Port and Scheme to use unencrypted TCP sockets. | ||
* @property {object} TCP_TLS Port and Scheme to use TLS-encrypted TCP sockets. | ||
* @property {object} WS Port and Scheme to use unencrypted WebSockets. | ||
* @property {object} WSS Port and Scheme to use TLS-encrypted WebSockets. | ||
*/ | ||
export const ElectrumTransport: { | ||
TCP: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
TCP_TLS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
WS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
WSS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
}; | ||
export const DefaultParameters: { | ||
PORT: number; | ||
TRANSPORT_SCHEME: TransportScheme; | ||
RECONNECT: number; | ||
TIMEOUT: number; | ||
PING_INTERVAL: number; | ||
CLUSTER_CONFIDENCE: number; | ||
CLUSTER_DISTRIBUTION: ClusterDistribution; | ||
CLUSTER_ORDER: ClusterOrder; | ||
}; | ||
/** | ||
* Isomorphic Socket interface supporting TCP sockets and WebSockets (Node and browser). | ||
@@ -179,6 +200,2 @@ * The interface is a subset of the TLSSocket interface with some slight modifications. | ||
/** | ||
* Clears the disconnect timer if it is still active. | ||
*/ | ||
private clearDisconnectTimerOnTimeout; | ||
/** | ||
* Forcibly terminate the connection. | ||
@@ -209,4 +226,2 @@ * | ||
} | ||
//# sourceMappingURL=electrum-socket.d.ts.map | ||
/** | ||
@@ -225,2 +240,3 @@ * Wrapper around TLS/WSS sockets that gracefully separates a network stream into Electrum protocol messages. | ||
pingInterval: number; | ||
reconnectInterval: number; | ||
socket: ElectrumSocket; | ||
@@ -245,6 +261,7 @@ lastReceivedTimestamp: number; | ||
* @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds. | ||
* @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds. | ||
* | ||
* @throws {Error} if `version` is not a valid version string. | ||
*/ | ||
constructor(application: string, version: string, host: string, port?: number, scheme?: TransportScheme, timeout?: number, pingInterval?: number); | ||
constructor(application: string, version: string, host: string, port?: number, scheme?: TransportScheme, timeout?: number, pingInterval?: number, reconnectInterval?: number); | ||
/** | ||
@@ -335,4 +352,2 @@ * Returns a string for the host identifier for usage in debug messages. | ||
} | ||
//# sourceMappingURL=electrum-connection.d.ts.map | ||
/** | ||
@@ -349,10 +364,12 @@ * Triggers when the underlying connection is established. | ||
/** | ||
* Triggers when the remote server sends data that is not a request response. | ||
* | ||
* @event ElectrumClient#notification | ||
*/ | ||
/** | ||
* High-level Electrum client that lets applications send requests and subscribe to notification events from a server. | ||
*/ | ||
declare class ElectrumClient extends EventEmitter { | ||
export class ElectrumClient extends EventEmitter { | ||
connection: ElectrumConnection; | ||
subscriptionMethods: { | ||
[index: string]: Array<string>; | ||
}; | ||
subscriptionCallbacks: WeakMap<object, SubscriptionTracker[]>; | ||
subscriptionMethods: Record<string, Set<string>>; | ||
requestId: number; | ||
@@ -362,2 +379,3 @@ requestResolvers: { | ||
}; | ||
connectionLock: Mutex; | ||
/** | ||
@@ -373,6 +391,7 @@ * Initializes an Electrum client. | ||
* @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds. | ||
* @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds. | ||
* | ||
* @throws {Error} if `version` is not a valid version string. | ||
*/ | ||
constructor(application: string, version: string, host: string, port?: number, scheme?: TransportScheme, timeout?: number, pingInterval?: number); | ||
constructor(application: string, version: string, host: string, port?: number, scheme?: TransportScheme, timeout?: number, pingInterval?: number, reconnectInterval?: number); | ||
/** | ||
@@ -405,5 +424,6 @@ * Connects to the remote server. | ||
/** | ||
* Subscribes to the method at the server and attaches the callback function to the event feed. | ||
* Subscribes to the method and payload at the server. | ||
* | ||
* @param {function} callback a function that should get notification messages. | ||
* @note the response for the subscription request is issued as a notification event. | ||
* | ||
* @param {string} method one of the subscribable methods the server supports. | ||
@@ -413,5 +433,5 @@ * @param {...string} parameters one or more parameters for the method. | ||
* @throws {Error} if the client is disconnected. | ||
* @returns a promise resolving to true when the subscription is set up. | ||
* @returns a promise resolving when the subscription is established. | ||
*/ | ||
subscribe(callback: SubscribeCallback, method: string, ...parameters: RPCParameter[]): Promise<true>; | ||
subscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
@@ -421,22 +441,11 @@ * Unsubscribes to the method at the server and removes any callback functions | ||
* | ||
* @param {function} callback a function that has previously been subscribed for this method. | ||
* @param {string} method a previously subscribed to method. | ||
* @param {...string} parameters one or more parameters for the method. | ||
* | ||
* @throws {Error} if no subscriptions exist for the combination of the passed `callback`, `method` and `parameters. | ||
* @throws {Error} if no subscriptions exist for the combination of the provided `method` and `parameters. | ||
* @throws {Error} if the client is disconnected. | ||
* @returns a promise that resolves to true when the subscription has been cancelled. | ||
* @returns a promise resolving when the subscription is removed. | ||
*/ | ||
unsubscribe(callback: SubscribeCallback, method: string, ...parameters: RPCParameter[]): Promise<true>; | ||
unsubscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
* Restores existing subscriptions without updating status or triggering manual callbacks. | ||
* | ||
* @throws {Error} if subscription data cannot be found for all stored event names. | ||
* @throws {Error} if the client is disconnected. | ||
* @returns a promise resolving to true when the subscriptions are restored. | ||
* | ||
* @ignore | ||
*/ | ||
private resubscribeOnConnect; | ||
/** | ||
* Parser messages from the remote server to resolve request promises and emit subscription events. | ||
@@ -458,4 +467,2 @@ * | ||
} | ||
//# sourceMappingURL=electrum-client.d.ts.map | ||
/** | ||
@@ -477,10 +484,18 @@ * Triggers when the cluster connects to enough servers to satisfy both the cluster confidence and distribution policies. | ||
/** | ||
* Triggers when the cluster verifies the integrity of remote server sent data that is not a request responses. | ||
* | ||
* @event ElectrumCluster#notification | ||
*/ | ||
/** | ||
* High-level electrum client that provides transparent load balancing, confidence checking and/or low-latency polling. | ||
*/ | ||
declare class ElectrumCluster extends EventEmitter { | ||
export class ElectrumCluster extends EventEmitter { | ||
application: string; | ||
version: string; | ||
confidence: number; | ||
distribution: number; | ||
order: ClusterOrder; | ||
timeout: number; | ||
pingInterval: number; | ||
strategy: ClusterStrategy; | ||
reconnectInterval: number; | ||
clients: { | ||
@@ -508,4 +523,5 @@ [index: string]: ClientConfig; | ||
* @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds. | ||
* @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds. | ||
*/ | ||
constructor(application: string, version: string, confidence?: number, distribution?: number, order?: ClusterOrder, timeout?: number, pingInterval?: number); | ||
constructor(application: string, version: string, confidence?: number, distribution?: number, order?: ClusterOrder, timeout?: number, pingInterval?: number, reconnectInterval?: number); | ||
/** | ||
@@ -537,3 +553,4 @@ * Adds a server to the cluster. | ||
* | ||
* @param {function} callback a function that should get notification messages. | ||
* @note the response for the subscription request is issued as a notification event. | ||
* | ||
* @param {string} method one of the subscribable methods the server supports. | ||
@@ -544,5 +561,4 @@ * @param {...string} parameters one or more parameters for the method. | ||
* @throws {Error} if no response is received with sufficient integrity for the initial request | ||
* @returns a promise resolving to true when the subscription is set up. | ||
*/ | ||
subscribe(callback: SubscribeCallback, method: string, ...parameters: RPCParameter[]): Promise<true>; | ||
subscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
@@ -552,12 +568,17 @@ * Unsubscribes to the method at the cluster and removes any callback functions | ||
* | ||
* @param {function} callback a function that has previously been subscribed for this method. | ||
* @deprecated | ||
* | ||
* @param {string} method one of the subscribable methods the server supports. | ||
* @param {...string} parameters one or more parameters for the method. | ||
* | ||
* @throws {Error} if, for any of the clients, no subscriptions exist for the combination of the | ||
* passed `callback`, `method` and `parameters. | ||
* @returns a promise resolving to true when the subscription has been cancelled. | ||
* @throws {Error} if, for any of the clients, no subscriptions exist for the combination of the provided `method` and `parameters. | ||
*/ | ||
unsubscribe(callback: SubscribeCallback, method: string, ...parameters: RPCParameter[]): Promise<true>; | ||
unsubscribe(method: string, ...parameters: RPCParameter[]): Promise<void>; | ||
/** | ||
* Define a callback function to validate server notifications and pass them to the subscribe callback. | ||
* | ||
* @ignore | ||
*/ | ||
handleSubscriptionNotifications(data: RPCNotification): Promise<void>; | ||
/** | ||
* Provides a method to check or wait for the cluster to become ready. | ||
@@ -586,42 +607,3 @@ * | ||
} | ||
//# sourceMappingURL=electrum-cluster.d.ts.map | ||
/** | ||
* Object containing the commonly used ports and schemes for specific Transports. | ||
* @example const electrum = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash', Transport.WSS.Port, Transport.WSS.Scheme); | ||
* | ||
* @property {object} TCP Port and Scheme to use unencrypted TCP sockets. | ||
* @property {object} TCP_TLS Port and Scheme to use TLS-encrypted TCP sockets. | ||
* @property {object} WS Port and Scheme to use unencrypted WebSockets. | ||
* @property {object} WSS Port and Scheme to use TLS-encrypted WebSockets. | ||
*/ | ||
declare const ElectrumTransport: { | ||
TCP: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
TCP_TLS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
WS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
WSS: { | ||
Port: number; | ||
Scheme: TransportScheme; | ||
}; | ||
}; | ||
declare const DefaultParameters: { | ||
PORT: number; | ||
TRANSPORT_SCHEME: TransportScheme; | ||
RECONNECT: number; | ||
TIMEOUT: number; | ||
PING_INTERVAL: number; | ||
CLUSTER_CONFIDENCE: number; | ||
CLUSTER_DISTRIBUTION: ClusterDistribution; | ||
CLUSTER_ORDER: ClusterOrder; | ||
}; | ||
export { ClientConfig, ClientState, ClusterDistribution, ClusterOrder, ClusterStatus, ClusterStrategy, ConnectionOptions, ConnectionStatus, DefaultParameters, ElectrumClient, ElectrumCluster, ElectrumTransport, RejectFunction, RequestResolver, RequestResponse, ResolveFunction, SubscribeCallback, SubscriptionTracker, TransportScheme, VersionNegotiated, VersionRejected, isVersionNegotiated, isVersionRejected }; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "electrum-cash", | ||
"version": "2.0.10", | ||
"version": "3.0.0", | ||
"description": "Electrum-cash is a lightweight JavaScript library that lets you connect with one or more Electrum servers.", | ||
"source": "lib/index.ts", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.mjs.js", | ||
"typings": "dist/index.d.ts", | ||
"directories": { | ||
"example": "examples", | ||
"test": "test" | ||
}, | ||
"browser": "dist/browser.cjs.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -16,15 +14,9 @@ "dist" | ||
"scripts": { | ||
"build": "npm run clean && npm run compile:main", | ||
"build:prepublish": "npm run clean && npm run compile && npm run rollup", | ||
"clean": "del ./dist", | ||
"compile": "npm run compile:main && npm run compile:module", | ||
"compile:main": "tsc", | ||
"compile:module": "tsc -p tsconfig.module.json", | ||
"build": "npm run clean && parcel build", | ||
"docs": "jsdoc -c jsdoc.json", | ||
"lint": "eslint . --ext .ts", | ||
"test": "npm run build && c8 ava test/**/*.test.ts", | ||
"docs": "jsdoc -c jsdoc.json", | ||
"prepublishOnly": "npm run build:prepublish", | ||
"rollup": "rollup -c", | ||
"postrollup": "del ./dist/module ./dist/main", | ||
"spellcheck": "cspell 'lib/**' 'test/**' 'examples/**'" | ||
"syntax": "tsc --noEmit", | ||
"spellcheck": "cspell 'lib/**' 'test/**' 'examples/**'", | ||
"test": "npm run build && c8 ava test/**/*.test.ts" | ||
}, | ||
@@ -54,27 +46,33 @@ "repository": { | ||
"devDependencies": { | ||
"@ava/typescript": "^1.1.1", | ||
"@ava/typescript": "^4.0.0", | ||
"@generalprotocols/cspell-dictionary": "git+https://gitlab.com/GeneralProtocols/cspell-dictionary.git", | ||
"@generalprotocols/eslint-config": "git+https://gitlab.com/GeneralProtocols/eslint-config.git", | ||
"@parcel/packager-ts": "^2.9.2", | ||
"@parcel/reporter-bundle-analyzer": "^2.9.2", | ||
"@parcel/transformer-typescript-types": "^2.9.2", | ||
"@types/debug": "^4.1.6", | ||
"@typescript-eslint/eslint-plugin": "^4.28.2", | ||
"ava": "^3.15.0", | ||
"better-docs": "^2.3.2", | ||
"c8": "^7.7.3", | ||
"cspell": "^5.6.6", | ||
"del-cli": "^4.0.0", | ||
"docdash": "^1.2.0", | ||
"eslint": "^7.30.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.11", | ||
"ava": "^5.3.0", | ||
"better-docs": "^2.7.2", | ||
"c8": "^8.0.0", | ||
"cspell": "^6.31.1", | ||
"del-cli": "^5.0.0", | ||
"docdash": "^2.0.1", | ||
"eslint": "^8.42.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"jsdoc": "^3.6.7", | ||
"rollup": "^2.53.0", | ||
"rollup-plugin-dts": "^3.0.2", | ||
"sinon": "^11.1.1", | ||
"typescript": "^4.3.5" | ||
"events": "^3.3.0", | ||
"jsdoc": "^4.0.2", | ||
"parcel": "^2.9.2", | ||
"process": "^0.11.10", | ||
"rollup": "^3.25.1", | ||
"rollup-plugin-dts": "^5.3.0", | ||
"sinon": "^15.1.2", | ||
"typescript": "^5.1.3" | ||
}, | ||
"dependencies": { | ||
"@types/ws": "^7.4.6", | ||
"async-mutex": "^0.3.1", | ||
"@types/ws": "^8.5.5", | ||
"async-mutex": "^0.4.0", | ||
"debug": "^4.3.2", | ||
"isomorphic-ws": "^4.0.1", | ||
"ws": "^7.5.2" | ||
"isomorphic-ws": "^5.0.0", | ||
"ws": "^8.13.0" | ||
}, | ||
@@ -86,3 +84,4 @@ "ava": { | ||
"./": "dist/main/" | ||
} | ||
}, | ||
"compile": false | ||
} | ||
@@ -89,0 +88,0 @@ }, |
@@ -93,10 +93,27 @@ # electrum-cash | ||
// Set up a callback function to handle new blocks. | ||
const handleNewBlocks = function(data) | ||
const handleNotifications = function(data) | ||
{ | ||
// Print out the block information. | ||
console.log(data); | ||
if(data.method === 'blockchain.headers.subscribe') | ||
{ | ||
// Print out the block information. | ||
// { | ||
// jsonrpc: '2.0', | ||
// method: 'blockchain.headers.subscribe', | ||
// params: | ||
// [ | ||
// { | ||
// height: 797111, | ||
// hex: '002001202a6b1367f68201ad957e95bec9bda3f132ca2fcb75c0c000000000000000000074befba60bd8615d87ddb636aa99bc032cec8db3adb0d915d45391bc811c1e9ceacf89647a60051819a79559' | ||
// } | ||
// ] | ||
// } | ||
console.log(data); | ||
} | ||
} | ||
// Set up a subscription for new block headers and handle events with our callback function. | ||
await electrum.subscribe(handleNewBlocks, 'blockchain.headers.subscribe'); | ||
// Listen for notifications. | ||
electrum.on('notification', handleNotifications); | ||
// Set up a subscription for new block headers. | ||
await electrum.subscribe('blockchain.headers.subscribe'); | ||
``` | ||
@@ -103,0 +120,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
624195
11
5111
151
24
1
+ Added@types/ws@8.5.12(transitive)
+ Addedasync-mutex@0.4.1(transitive)
+ Addedisomorphic-ws@5.0.0(transitive)
+ Addedws@8.18.0(transitive)
- Removed@types/ws@7.4.7(transitive)
- Removedasync-mutex@0.3.2(transitive)
- Removedisomorphic-ws@4.0.1(transitive)
- Removedws@7.5.10(transitive)
Updated@types/ws@^8.5.5
Updatedasync-mutex@^0.4.0
Updatedisomorphic-ws@^5.0.0
Updatedws@^8.13.0