Comparing version 0.2.2 to 0.2.6
@@ -11,3 +11,3 @@ import { Buffer } from 'buffer'; | ||
export function ecdh(pubkey, privkey) { | ||
const point = secp256k1.Point.fromHex(secp256k1.getSharedSecret(privkey, pubkey)); | ||
const point = secp256k1.ProjectivePoint.fromHex(secp256k1.getSharedSecret(privkey, pubkey)); | ||
return Buffer.from(sha256(point.toRawBytes(true))); | ||
@@ -90,3 +90,3 @@ } | ||
try { | ||
secp256k1.Point.fromHex(publicKey); | ||
secp256k1.ProjectivePoint.fromHex(publicKey); | ||
return true; | ||
@@ -93,0 +93,0 @@ } |
@@ -69,4 +69,6 @@ /// <reference types="node" /> | ||
private _l; | ||
private _pingTimeout; | ||
constructor(options: LnWebSocketOptions); | ||
connect(attemptReconnect?: boolean): Promise<boolean>; | ||
private _sendPingMessage; | ||
private queueMessage; | ||
@@ -73,0 +75,0 @@ disconnect(): void; |
@@ -11,2 +11,3 @@ import { BehaviorSubject, firstValueFrom, Subject } from 'rxjs'; | ||
import { PongMessage } from './messages/PongMessage.js'; | ||
import { PingMessage } from './messages/PingMessage.js'; | ||
import { HANDSHAKE_STATE, READ_STATE, MessageType } from './types.js'; | ||
@@ -71,2 +72,3 @@ const DEFAULT_RECONNECT_ATTEMPTS = 5; | ||
_l; | ||
_pingTimeout; | ||
constructor(options) { | ||
@@ -103,2 +105,3 @@ validateInit(options); | ||
this._l = null; | ||
this._pingTimeout = null; | ||
this.decryptedMsgs$.subscribe((msg) => { | ||
@@ -141,5 +144,7 @@ this.handleDecryptedMessage(msg); | ||
} | ||
this._pingTimeout = setTimeout(this._sendPingMessage.bind(this), 45 * 1000); | ||
}; | ||
this.socket.onclose = async () => { | ||
this._log('error', 'WebSocket is closed at ' + new Date().toISOString()); | ||
this._pingTimeout && clearTimeout(this._pingTimeout); | ||
this.connectionStatus$.next('disconnected'); | ||
@@ -163,2 +168,10 @@ this.connected$.next(false); | ||
} | ||
_sendPingMessage() { | ||
const pongMessage = new PingMessage().serialize(); | ||
const ping = this.noise.encryptMessage(pongMessage); | ||
if (this.socket) { | ||
this._log('info', 'Sending a Ping message'); | ||
this.socket.send(ping); | ||
} | ||
} | ||
queueMessage(event) { | ||
@@ -305,2 +318,5 @@ const { data } = event; | ||
async handleDecryptedMessage(decrypted) { | ||
// reset ping timeout | ||
this._pingTimeout && clearTimeout(this._pingTimeout); | ||
this._pingTimeout = setTimeout(this._sendPingMessage.bind(this), 40 * 1000); | ||
try { | ||
@@ -307,0 +323,0 @@ const reader = new BufferReader(decrypted); |
/// <reference types="node" /> | ||
import { Buffer } from 'buffer'; | ||
declare type BigIntInput = string | number | bigint | boolean; | ||
type BigIntInput = string | number | bigint | boolean; | ||
/** | ||
@@ -5,0 +5,0 @@ * BitField assists with using bit flags to set or unset values in the bit |
@@ -15,2 +15,3 @@ //**Wraps a TCP socket with the WebSocket API */ | ||
this.onclose && this.onclose(); | ||
socket.removeAllListeners(); | ||
}); | ||
@@ -27,4 +28,3 @@ socket.on('error', (error) => { | ||
this.close = () => { | ||
socket.removeAllListeners(); | ||
socket.destroy(); | ||
socket.end(); | ||
}; | ||
@@ -31,0 +31,0 @@ const url = new URL(connection); |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
import type { Socket as TCPSocket } from 'net'; | ||
export declare type LnWebSocketOptions = { | ||
export type LnWebSocketOptions = { | ||
/** | ||
@@ -43,3 +43,3 @@ * 33-byte hex remote compressed public key. | ||
}; | ||
export declare type NoiseStateOptions = { | ||
export type NoiseStateOptions = { | ||
/** | ||
@@ -133,3 +133,3 @@ * Local private key as a 32-byte buffer | ||
} | ||
export declare type JsonRpcRequest = { | ||
export type JsonRpcRequest = { | ||
/**The RPC method you would like to call*/ | ||
@@ -144,10 +144,10 @@ method: string; | ||
}; | ||
declare type JsonRpcBaseResponse = { | ||
type JsonRpcBaseResponse = { | ||
jsonrpc: string; | ||
id: string | number | null; | ||
}; | ||
export declare type JsonRpcSuccessResponse = JsonRpcBaseResponse & { | ||
export type JsonRpcSuccessResponse = JsonRpcBaseResponse & { | ||
result: unknown; | ||
}; | ||
export declare type JsonRpcErrorResponse = JsonRpcBaseResponse & { | ||
export type JsonRpcErrorResponse = JsonRpcBaseResponse & { | ||
error: { | ||
@@ -159,3 +159,3 @@ code: number; | ||
}; | ||
export declare type CommandoRequest = JsonRpcRequest & { | ||
export type CommandoRequest = JsonRpcRequest & { | ||
/**Base64 encoded rune token as outputted by the commando-rune cli command | ||
@@ -172,4 +172,4 @@ * If the rune does not have adequate permissions for this request an error will | ||
}; | ||
export declare type CommandoResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse; | ||
export declare type Logger = { | ||
export type CommandoResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse; | ||
export type Logger = { | ||
info: (msg: string) => void; | ||
@@ -179,3 +179,3 @@ warn: (msg: string) => void; | ||
}; | ||
export declare type ConnectionStatus = 'connected' | 'connecting' | 'disconnected' | 'waiting_reconnect'; | ||
export type ConnectionStatus = 'connected' | 'connecting' | 'disconnected' | 'waiting_reconnect'; | ||
export {}; |
@@ -8,4 +8,4 @@ import { validPrivateKey, validPublicKey } from './crypto.js'; | ||
const ipRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/; | ||
const domainRegex = /^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$/; | ||
if (!ip || (!ip.match(ipRegex) && !ip.match(domainRegex) && ip !== 'localhost')) { | ||
const dnsRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/; | ||
if (!ip || (!ip.match(ipRegex) && !ip.match(dnsRegex) && ip !== 'localhost')) { | ||
throw new Error(`${ip} is not a valid IP or DNS address`); | ||
@@ -12,0 +12,0 @@ } |
{ | ||
"name": "lnmessage", | ||
"version": "0.2.2", | ||
"version": "0.2.6", | ||
"description": "Talk to Lightning nodes from your browser", | ||
@@ -19,3 +19,2 @@ "main": "dist/index.js", | ||
"@types/node": "^18.14.0", | ||
"@types/secp256k1": "^4.0.3", | ||
"@types/ws": "^8.5.4", | ||
@@ -27,11 +26,11 @@ "@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"prettier": "^2.6.2", | ||
"typescript": "^4.8.2" | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"@noble/hashes": "^1.2.0", | ||
"@noble/secp256k1": "^1.7.1", | ||
"@noble/hashes": "^1.3.1", | ||
"@noble/secp256k1": "^2.0.0", | ||
"buffer": "^6.0.3", | ||
"rxjs": "^7.5.7", | ||
"ws": "^8.12.1" | ||
"ws": "^8.13.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
256293
8
4388
+ Added@noble/secp256k1@2.1.0(transitive)
- Removed@noble/secp256k1@1.7.1(transitive)
Updated@noble/hashes@^1.3.1
Updated@noble/secp256k1@^2.0.0
Updatedws@^8.13.0