@samouraiwallet/electrum-client
Advanced tools
Comparing version 1.2.4 to 1.3.0
# Changelog | ||
## 1.3.0 (2022-12-08) | ||
- Updated TLS wrapper | ||
- Updated dependencies | ||
- Switched from mocha to vitest | ||
## 1.2.4 (2022-03-11) | ||
@@ -4,0 +9,0 @@ - Fixed type of protocol version in config |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { EventEmitter } from 'node:events'; | ||
import { Protocol, Callbacks, ElectrumRequestBatchParams, ElectrumRequestParams } from '../types'; | ||
@@ -4,0 +4,0 @@ export declare abstract class Client { |
@@ -1,3 +0,3 @@ | ||
import net from 'net'; | ||
import { EventEmitter } from 'events'; | ||
import net from 'node:net'; | ||
import { EventEmitter } from 'node:events'; | ||
import { TlsSocketWrapper } from './tls-socket-wrapper.js'; | ||
@@ -4,0 +4,0 @@ import * as util from './util.js'; |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
export declare class TlsSocketWrapper extends EventEmitter { | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as dns from 'node:dns'; | ||
import net from 'node:net'; | ||
interface OnReadOpts { | ||
buffer: Uint8Array | (() => Uint8Array); | ||
callback(bytesWritten: number, buf: Uint8Array): boolean; | ||
} | ||
type LookupFunction = (hostname: string, options: dns.LookupOneOptions, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void) => void; | ||
interface ConnectOpts { | ||
onread?: OnReadOpts | undefined; | ||
} | ||
interface TcpSocketConnectOpts extends ConnectOpts { | ||
port: number; | ||
host?: string | undefined; | ||
localAddress?: string | undefined; | ||
localPort?: number | undefined; | ||
hints?: number | undefined; | ||
family?: number | undefined; | ||
lookup?: LookupFunction | undefined; | ||
noDelay?: boolean | undefined; | ||
keepAlive?: boolean | undefined; | ||
keepAliveInitialDelay?: number | undefined; | ||
} | ||
interface IpcSocketConnectOpts extends ConnectOpts { | ||
path: string; | ||
} | ||
type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts; | ||
export declare class TlsSocketWrapper extends net.Socket { | ||
private _socket; | ||
@@ -11,11 +39,12 @@ private _timeout; | ||
constructor(); | ||
setTimeout(timeout: number): void; | ||
setEncoding(encoding: BufferEncoding): void; | ||
setKeepAlive(enabled: boolean, initialDelay: number): void; | ||
setNoDelay(noDelay: boolean): void; | ||
connect(port: number, host: string, callback: () => void): void; | ||
end(): void; | ||
destroy(): void; | ||
write(data: string | Uint8Array): void; | ||
setTimeout(timeout: number, callback?: () => void): this; | ||
setEncoding(encoding: BufferEncoding): this; | ||
setKeepAlive(enabled: boolean, initialDelay: number): this; | ||
setNoDelay(noDelay: boolean): this; | ||
connect(optionsOrPathOrPort: number | string | SocketConnectOpts, hostOrConnectionListener?: string | (() => void), connectionListener?: () => void): this; | ||
end(): this; | ||
destroy(): this; | ||
write(data: string | Uint8Array): boolean; | ||
} | ||
export {}; | ||
//# sourceMappingURL=tls-socket-wrapper.d.ts.map |
@@ -1,4 +0,5 @@ | ||
import tls from 'tls'; | ||
import { EventEmitter } from 'events'; | ||
export class TlsSocketWrapper extends EventEmitter { | ||
import tls from 'node:tls'; | ||
import net from 'node:net'; | ||
const isIpcSocketConnectOpts = (opts) => 'path' in opts; | ||
export class TlsSocketWrapper extends net.Socket { | ||
constructor() { | ||
@@ -13,6 +14,9 @@ super(); | ||
} | ||
setTimeout(timeout) { | ||
setTimeout(timeout, callback) { | ||
if (this._socket) | ||
this._socket.setTimeout(timeout); | ||
this._timeout = timeout; | ||
if (callback) | ||
callback(); | ||
return this; | ||
} | ||
@@ -23,2 +27,3 @@ setEncoding(encoding) { | ||
this._encoding = encoding; | ||
return this; | ||
} | ||
@@ -30,2 +35,3 @@ setKeepAlive(enabled, initialDelay) { | ||
this._keepAliveinitialDelay = initialDelay; | ||
return this; | ||
} | ||
@@ -36,6 +42,29 @@ setNoDelay(noDelay) { | ||
this._noDelay = noDelay; | ||
return this; | ||
} | ||
connect(port, host, callback) { | ||
connect(optionsOrPathOrPort, hostOrConnectionListener, connectionListener) { | ||
if (typeof optionsOrPathOrPort === 'string') | ||
throw new Error('Not implemented'); | ||
let port; | ||
let host; | ||
let callback; | ||
if (typeof optionsOrPathOrPort === 'object') { | ||
if (isIpcSocketConnectOpts(optionsOrPathOrPort)) | ||
throw new Error('Not implemented'); | ||
port = optionsOrPathOrPort.port; | ||
host = optionsOrPathOrPort.host ?? 'localhost'; | ||
} | ||
else { | ||
port = optionsOrPathOrPort; | ||
host = typeof hostOrConnectionListener === 'string' ? hostOrConnectionListener : 'localhost'; | ||
} | ||
if (typeof hostOrConnectionListener === 'function') { | ||
callback = hostOrConnectionListener; | ||
} | ||
else if (typeof connectionListener === 'function') { | ||
callback = connectionListener; | ||
} | ||
this._socket = tls.connect({ port: port, host: host, rejectUnauthorized: false }, () => { | ||
return callback(); | ||
if (callback) | ||
callback(); | ||
}); | ||
@@ -61,13 +90,16 @@ this._socket.setTimeout(this._timeout); | ||
}); | ||
return this; | ||
} | ||
end() { | ||
this._socket && this._socket.end(); | ||
return this; | ||
} | ||
destroy() { | ||
this._socket && this._socket.destroy(); | ||
return this; | ||
} | ||
write(data) { | ||
this._socket && this._socket.write(data); | ||
return this._socket ? this._socket.write(data) : false; | ||
} | ||
} | ||
//# sourceMappingURL=tls-socket-wrapper.js.map |
@@ -9,4 +9,4 @@ /// <reference types="node" /> | ||
export declare const createPromiseResult: (resolve: (value?: any) => void, reject: (reason?: any) => void) => (err: Error | null, result?: any) => void; | ||
export declare const createPromiseResultBatch: (resolve: (value?: any) => void, reject: (reason?: any) => void, argz: Record<number, any>) => (err: Error | null, result?: any[] | undefined) => void; | ||
declare type MessageParserCallback = (body: string | undefined, n: number) => void; | ||
export declare const createPromiseResultBatch: (resolve: (value?: any) => void, reject: (reason?: any) => void, argz: Record<number, any>) => (err: Error | null, result?: Array<any>) => void; | ||
type MessageParserCallback = (body: string | undefined, n: number) => void; | ||
export declare class MessageParser { | ||
@@ -13,0 +13,0 @@ private buffer; |
import { ElectrumClient } from '../index.js'; | ||
export declare type Protocol = 'tcp' | 'tls' | 'ssl'; | ||
export declare type Callbacks = { | ||
export type Protocol = 'tcp' | 'tls' | 'ssl'; | ||
export type Callbacks = { | ||
onConnect?: (client: ElectrumClient, versionInfo: [string, string]) => void; | ||
@@ -9,3 +9,3 @@ onClose?: (client: ElectrumClient) => void; | ||
}; | ||
export declare type PersistencePolicy = { | ||
export type PersistencePolicy = { | ||
retryPeriod?: number; | ||
@@ -16,8 +16,8 @@ maxRetry?: number; | ||
}; | ||
export declare type ElectrumConfig = { | ||
export type ElectrumConfig = { | ||
client: string; | ||
version: string | [string, string]; | ||
}; | ||
export declare type ElectrumRequestParams = Array<number | string | boolean | Array<any>>; | ||
export declare type ElectrumRequestBatchParams = number | string | boolean | undefined; | ||
export type ElectrumRequestParams = Array<number | string | boolean | Array<any>>; | ||
export type ElectrumRequestBatchParams = number | string | boolean | undefined; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@samouraiwallet/electrum-client", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"engines": { | ||
@@ -17,3 +17,4 @@ "node": ">=14.0.0" | ||
"scripts": { | ||
"test": "mocha", | ||
"test": "vitest run", | ||
"test:watch": "vitest watch", | ||
"lint": "eslint --ext .ts src/", | ||
@@ -38,13 +39,12 @@ "typescript": "tsc --noEmit", | ||
"devDependencies": { | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^14.18.12", | ||
"@typescript-eslint/eslint-plugin": "^5.12.1", | ||
"@typescript-eslint/parser": "^5.12.1", | ||
"eslint": "^8.10.0", | ||
"@types/node": "^16.18.6", | ||
"@typescript-eslint/eslint-plugin": "^5.46.0", | ||
"@typescript-eslint/parser": "^5.46.0", | ||
"@vitest/coverage-c8": "^0.25.6", | ||
"eslint": "^8.29.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-unicorn": "^41.0.0", | ||
"mocha": "^9.2.1", | ||
"ts-node": "^10.5.0", | ||
"typescript": "^4.5.5" | ||
"eslint-plugin-unicorn": "^45.0.1", | ||
"typescript": "^4.9.4", | ||
"vitest": "^0.25.6" | ||
} | ||
} |
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
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
9
716
0
37769
14