@electrum-cash/network 4.0.0-development.6655313659 → 4.0.0-development.8017810652

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter } from "events";
2
+ import { ElectrumSocket } from "@electrum-cash/sockets";
2
3
  type RPCParameter = string | number | boolean | null;
3
4
  interface RPCBase {
4
5
  jsonrpc: string;
@@ -47,69 +48,51 @@ export enum ConnectionStatus {
47
48
  CONNECTING = 3,
48
49
  RECONNECTING = 4
49
50
  }
50
- export interface ClientConfig {
51
- state: ClientState;
52
- connection: ElectrumClient;
53
- }
54
51
  /**
55
52
  * A list of possible responses to requests.
53
+ * @ignore
56
54
  */
57
55
  export type RequestResponse = object | string | number | boolean | null | RequestResponse[];
56
+ /**
57
+ * Request resolvers are used to process the response of a request. This takes either
58
+ * an error object or any stringified data, while the other parameter is omitted.
59
+ * @ignore
60
+ */
58
61
  export type RequestResolver = (error?: Error, data?: string) => void;
62
+ /**
63
+ * Typing for promise resolution.
64
+ * @ignore
65
+ */
59
66
  export type ResolveFunction<T> = (value: T | PromiseLike<T>) => void;
67
+ /**
68
+ * Typing for promise rejection.
69
+ * @ignore
70
+ */
60
71
  export type RejectFunction = (reason?: any) => void;
72
+ /**
73
+ * @ignore
74
+ */
61
75
  export interface VersionRejected {
62
76
  error: RPCError;
63
77
  }
78
+ /**
79
+ * @ignore
80
+ */
64
81
  export interface VersionNegotiated {
65
82
  software: string;
66
83
  protocol: string;
67
84
  }
68
- export const isVersionRejected: (object: any) => object is VersionRejected;
69
- export const isVersionNegotiated: (object: any) => object is VersionNegotiated;
70
85
  /**
71
- * Possible Transport Schemes for communication with the Electrum server
86
+ * @ignore
72
87
  */
73
- export type TransportScheme = 'tcp' | 'tcp_tls' | 'ws' | 'wss';
74
- export interface ConnectionOptions {
75
- rejectUnauthorized?: boolean;
76
- serverName?: string;
77
- }
88
+ export const isVersionRejected: (object: any) => object is VersionRejected;
78
89
  /**
79
- * Object containing the commonly used ports and schemes for specific Transports.
80
- * @example const electrum = new ElectrumClient('Electrum client example', '1.4.1', 'bch.imaginary.cash', Transport.WSS.Port, Transport.WSS.Scheme);
81
- *
82
- * @property {object} TCP Port and Scheme to use unencrypted TCP sockets.
83
- * @property {object} TCP_TLS Port and Scheme to use TLS-encrypted TCP sockets.
84
- * @property {object} WS Port and Scheme to use unencrypted WebSockets.
85
- * @property {object} WSS Port and Scheme to use TLS-encrypted WebSockets.
90
+ * @ignore
86
91
  */
87
- export const ElectrumTransport: {
88
- TCP: {
89
- Port: number;
90
- Scheme: TransportScheme;
91
- };
92
- TCP_TLS: {
93
- Port: number;
94
- Scheme: TransportScheme;
95
- };
96
- WS: {
97
- Port: number;
98
- Scheme: TransportScheme;
99
- };
100
- WSS: {
101
- Port: number;
102
- Scheme: TransportScheme;
103
- };
104
- };
105
- export const DefaultParameters: {
106
- PORT: number;
107
- TRANSPORT_SCHEME: TransportScheme;
108
- RECONNECT: number;
109
- TIMEOUT: number;
110
- PING_INTERVAL: number;
111
- USE_BIG_INT: boolean;
112
- };
92
+ export const isVersionNegotiated: (object: any) => object is VersionNegotiated;
93
+ export const DEFAULT_PING_INTERVAL: number;
94
+ export const DEFAULT_RECONNECT_INTERVAL: number;
95
+ export const DEFAULT_BIG_INTEGERS = false;
113
96
  /**
114
97
  * Triggers when the underlying connection is established.
115
98
  *
@@ -131,10 +114,7 @@ export const DefaultParameters: {
131
114
  export class ElectrumClient extends EventEmitter {
132
115
  application: string;
133
116
  version: string;
134
- host: string;
135
- port: number;
136
- scheme: TransportScheme;
137
- timeout: number;
117
+ socketOrHostname: ElectrumSocket | string;
138
118
  pingInterval: number;
139
119
  reconnectInterval: number;
140
120
  useBigInt: boolean;
@@ -163,19 +143,18 @@ export class ElectrumClient extends EventEmitter {
163
143
  /**
164
144
  * Initializes an Electrum client.
165
145
  *
166
- * @param {string} application your application name, used to identify to the electrum host.
167
- * @param {string} version protocol version to use with the host.
168
- * @param {string} host fully qualified domain name or IP number of the host.
169
- * @param {number} port the TCP network port of the host.
170
- * @param {TransportScheme} scheme the transport scheme to use for connection
171
- * @param {number} timeout how long network delays we will wait for before taking action, in milliseconds.
172
- * @param {number} pingInterval the time between sending pings to the electrum host, in milliseconds.
173
- * @param {number} reconnectInterval the time between reconnection attempts to the electrum host, in milliseconds.
174
- * @param {boolean} useBigInt whether to use bigint for numbers in json response.
146
+ * @param application - your application name, used to identify to the electrum host.
147
+ * @param version - protocol version to use with the host.
148
+ * @param socketOrHostname - pre-configured electrum socket or fully qualified domain name or IP number of the host
149
+ * @param pingInterval - the time between sending pings to the electrum host, in milliseconds.
150
+ * @param reconnectInterval - the time between reconnection attempts to the electrum host, in milliseconds.
151
+ * @param useBigInt - whether to use bigint for numbers in json response.
175
152
  *
176
153
  * @throws {Error} if `version` is not a valid version string.
177
154
  */
178
- constructor(application: string, version: string, host: string, port?: number, scheme?: TransportScheme, timeout?: number, pingInterval?: number, reconnectInterval?: number, useBigInt?: boolean);
155
+ constructor(application: string, version: string, socketOrHostname: ElectrumSocket | string, pingInterval?: number, reconnectInterval?: number, useBigInt?: boolean);
156
+ get hostIdentifier(): string;
157
+ get encrypted(): boolean;
179
158
  /**
180
159
  * Connects to the remote server.
181
160
  *
@@ -186,8 +165,8 @@ export class ElectrumClient extends EventEmitter {
186
165
  /**
187
166
  * Disconnects from the remote server and removes all event listeners/subscriptions and open requests.
188
167
  *
189
- * @param {boolean} force disconnect even if the connection has not been fully established yet.
190
- * @param {boolean} retainSubscriptions retain subscription data so they will be restored on reconnection.
168
+ * @param force - disconnect even if the connection has not been fully established yet.
169
+ * @param retainSubscriptions - retain subscription data so they will be restored on reconnection.
191
170
  *
192
171
  * @returns true if successfully disconnected, or false if there was no connection.
193
172
  */
@@ -195,8 +174,8 @@ export class ElectrumClient extends EventEmitter {
195
174
  /**
196
175
  * Calls a method on the remote server with the supplied parameters.
197
176
  *
198
- * @param {string} method name of the method to call.
199
- * @param {...string} parameters one or more parameters for the method.
177
+ * @param method - name of the method to call.
178
+ * @param parameters - one or more parameters for the method.
200
179
  *
201
180
  * @throws {Error} if the client is disconnected.
202
181
  * @returns a promise that resolves with the result of the method or an Error.
@@ -207,8 +186,8 @@ export class ElectrumClient extends EventEmitter {
207
186
  *
208
187
  * @note the response for the subscription request is issued as a notification event.
209
188
  *
210
- * @param {string} method one of the subscribable methods the server supports.
211
- * @param {...string} parameters one or more parameters for the method.
189
+ * @param method - one of the subscribable methods the server supports.
190
+ * @param parameters - one or more parameters for the method.
212
191
  *
213
192
  * @throws {Error} if the client is disconnected.
214
193
  * @returns a promise resolving when the subscription is established.
@@ -218,8 +197,8 @@ export class ElectrumClient extends EventEmitter {
218
197
  * Unsubscribes to the method at the server and removes any callback functions
219
198
  * when there are no more subscriptions for the method.
220
199
  *
221
- * @param {string} method a previously subscribed to method.
222
- * @param {...string} parameters one or more parameters for the method.
200
+ * @param method - a previously subscribed to method.
201
+ * @param parameters - one or more parameters for the method.
223
202
  *
224
203
  * @throws {Error} if no subscriptions exist for the combination of the provided `method` and `parameters.
225
204
  * @throws {Error} if the client is disconnected.
@@ -229,7 +208,7 @@ export class ElectrumClient extends EventEmitter {
229
208
  /**
230
209
  * Parser messages from the remote server to resolve request promises and emit subscription events.
231
210
  *
232
- * @param {RPCNotification | RPCResponse} message the response message
211
+ * @param message - the response message
233
212
  *
234
213
  * @throws {Error} if the message ID does not match an existing request.
235
214
  * @ignore
@@ -1 +1 @@
1
- {"mappings":";ACCA,oBAA2B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAG5D;IAEC,OAAO,EAAE,MAAM,CAAC;CAChB;AAGD,yBAAiC,SAAQ,OAAO;IAE/C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB;AAWD,sBAA8B,SAAQ,OAAO;IAE5C,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,M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AG,eAAe,CAAC;IAgD9F;;;;;;;;;;OAUG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7E;;;;;;;;;;OAUG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgF/E;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,GAAG,IAAI;IA0DtD;;;;;OAKG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB7C;;;;OAIG;IACG,oBAAoB,CAAC,gBAAgB,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAa3D;;;;OAIG;IACG,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlD;;;;;OAKG;IACG,yCAAyC,CAAC,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvE;;;;;OAKG;IACG,oCAAoC,CAAC,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;OAEG;IACG,6BAA6B,CAAC,SAAS,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ7D","sources":["source/source/util.ts","source/source/rpc-interfaces.ts","source/source/electrum-protocol.ts","source/source/enums.ts","source/source/interfaces.ts","source/source/constants.ts","source/source/electrum-socket.ts","source/source/electrum-connection.ts","source/source/electrum-client.ts","source/source/index.ts","source/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './constants';\nexport * from './enums';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;AACA,oBAA2B,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAG5D;IAEC,OAAO,EAAE,MAAM,CAAC;CAChB;AAGD,yBAAiC,SA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;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7E;;;;;;;;;;OAUG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgF/E;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,WAAW,GAAG,IAAI;IA0DtD;;;;;OAKG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB7C;;;;OAIG;IACG,oBAAoB,CAAC,gBAAgB,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAa3D;;;;OAIG;IACG,2BAA2B,IAAI,OAAO,CAAC,IAAI,CAAC;IAMlD;;;;;OAKG;IACG,yCAAyC,CAAC,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvE;;;;;OAKG;IACG,oCAAoC,CAAC,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;OAEG;IACG,6BAA6B,CAAC,SAAS,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ7D","sources":["source/source/rpc-interfaces.ts","source/source/electrum-protocol.ts","source/source/enums.ts","source/source/interfaces.ts","source/source/constants.ts","source/source/electrum-connection.ts","source/source/electrum-client.ts","source/source/index.ts","source/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"export { default as ElectrumClient } from './electrum-client';\n\nexport * from './interfaces';\nexport * from './constants';\nexport * from './enums';\n"],"names":[],"version":3,"file":"index.d.ts.map"}