Socket
Socket
Sign inDemoInstall

lnmessage

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lnmessage - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

dist/socket-wrapper.d.ts

2

dist/crypto.d.ts
/// <reference types="node" />
import { Buffer } from 'buffer';
export declare function sha256(input: Buffer): Buffer;
export declare function sha256(input: Uint8Array): Buffer;
export declare function ecdh(pubkey: Uint8Array, privkey: Uint8Array): Buffer;

@@ -5,0 +5,0 @@ export declare function hmacHash(key: Buffer, input: Buffer): Buffer;

import { Buffer } from 'buffer';
import secp256k1 from 'secp256k1';
import * as secp256k1 from '@noble/secp256k1';
import { createCipher, createDecipher } from './chacha/index.js';

@@ -11,3 +11,4 @@ import { hmac } from '@noble/hashes/hmac';

export function ecdh(pubkey, privkey) {
return Buffer.from(secp256k1.ecdh(pubkey, privkey));
const point = secp256k1.Point.fromHex(secp256k1.getSharedSecret(privkey, pubkey));
return Buffer.from(sha256(point.toRawBytes(true)));
}

@@ -33,3 +34,3 @@ export function hmacHash(key, input) {

export function getPublicKey(privKey, compressed = true) {
return Buffer.from(secp256k1.publicKeyCreate(privKey, compressed));
return Buffer.from(secp256k1.getPublicKey(privKey, compressed));
}

@@ -89,6 +90,12 @@ /**

export function validPublicKey(publicKey) {
return secp256k1.publicKeyVerify(Buffer.from(publicKey, 'hex'));
try {
secp256k1.Point.fromHex(publicKey);
return true;
}
catch (e) {
return false;
}
}
export function validPrivateKey(privateKey) {
return secp256k1.privateKeyVerify(typeof privateKey === 'string' ? Buffer.from(privateKey, 'hex') : privateKey);
return secp256k1.utils.isValidPrivateKey(privateKey);
}

@@ -95,0 +102,0 @@ export function createRandomBytes(length) {

/// <reference types="node" />
/// <reference types="node" />
import { BehaviorSubject, Observable } from 'rxjs';

@@ -6,2 +7,4 @@ import { Buffer } from 'buffer';

import type { WebSocket as NodeWebSocket } from 'ws';
import type { Socket as TCPSocket } from 'net';
import type SocketWrapper from './socket-wrapper.js';
import { LnWebSocketOptions, JsonRpcSuccessResponse, JsonRpcErrorResponse, Logger, CommandoRequest, ConnectionStatus } from './types.js';

@@ -28,3 +31,5 @@ declare class LnMessage {

/**The WebSocket instance*/
socket: WebSocket | NodeWebSocket | null;
socket: WebSocket | NodeWebSocket | null | SocketWrapper;
/**TCP socket instance*/
tcpSocket?: TCPSocket;
/**

@@ -31,0 +36,0 @@ * @deprecated Use connectionStatus$ instead

@@ -34,2 +34,4 @@ import { BehaviorSubject, firstValueFrom, Subject } from 'rxjs';

socket;
/**TCP socket instance*/
tcpSocket;
/**

@@ -71,3 +73,3 @@ * @deprecated Use connectionStatus$ instead

validateInit(options);
const { remoteNodePublicKey, wsProxy, wsProtocol = 'wss:', privateKey, ip, port = 9735, logger } = options;
const { remoteNodePublicKey, wsProxy, wsProtocol = 'wss:', privateKey, ip, port = 9735, logger, tcpSocket } = options;
this._ls = Buffer.from(privateKey || createRandomPrivateKey(), 'hex');

@@ -87,2 +89,3 @@ this._es = Buffer.from(createRandomPrivateKey(), 'hex');

this.Buffer = Buffer;
this.tcpSocket = tcpSocket;
this._handshakeState = HANDSHAKE_STATE.INITIATOR_INITIATING;

@@ -119,4 +122,11 @@ this._decryptedMsgs$ = new Subject();

this._attemptReconnect = attemptReconnect;
this.socket = new (typeof window === 'undefined' ? (await import('ws')).default : window.WebSocket)(this.wsUrl);
this.socket.binaryType = 'arraybuffer';
this.socket = this.tcpSocket
? new (await import('./socket-wrapper.js')).default(this.wsUrl, this.tcpSocket)
: typeof globalThis.WebSocket === 'undefined'
? new (await import('ws')).default(this.wsUrl)
: new globalThis.WebSocket(this.wsUrl);
if (this.socket.binaryType) {
;
this.socket.binaryType = 'arraybuffer';
}
this.socket.onopen = async () => {

@@ -123,0 +133,0 @@ this._log('info', 'WebSocket is connected');

@@ -118,3 +118,3 @@ import { Buffer } from 'buffer';

this.ck = tempK1.subarray(0, 32);
this.tempK1 = tempK1.subarray(32);
this.tempK1 = Buffer.from(tempK1.subarray(32));
// 5. c = encryptWithAD(temp_k1, 0, h, zero)

@@ -177,3 +177,3 @@ const c = ccpEncrypt(this.tempK1, Buffer.alloc(12), this.h, Buffer.alloc(0));

this.ck = tempK3.subarray(0, 32);
this.tempK3 = tempK3.subarray(32);
this.tempK3 = Buffer.from(tempK3.subarray(32));
// 5. t = encryptWithAD(temp_k3, 0, h, zero)

@@ -236,3 +236,3 @@ const t = ccpEncrypt(this.tempK3, Buffer.alloc(12), this.h, Buffer.alloc(0));

this.ck = tempK2.subarray(0, 32);
this.tempK2 = tempK2.subarray(32);
this.tempK2 = Buffer.from(tempK2.subarray(32));
// 5. c = encryptWithAd(temp_k2, 0, h, zero)

@@ -239,0 +239,0 @@ const c = ccpEncrypt(this.tempK2, Buffer.alloc(12), this.h, Buffer.alloc(0));

/// <reference types="node" />
/// <reference types="node" />
import type { Buffer } from 'buffer';
import type { Socket as TCPSocket } from 'net';
export declare type LnWebSocketOptions = {

@@ -28,2 +30,4 @@ /**

wsProtocol?: 'ws:' | 'wss:';
/**In nodejs or react native you can connect directly via a TCP socket */
tcpSocket?: TCPSocket;
/**

@@ -30,0 +34,0 @@ * 32 byte hex encoded private key to be used as the local node secret.

{
"name": "lnmessage",
"version": "0.1.0",
"version": "0.2.0",
"description": "Talk to Lightning nodes from your browser",

@@ -13,2 +13,3 @@ "main": "dist/index.js",

"license": "MIT",
"repository": "github:aaronbarnardsound/lnmessage",
"scripts": {

@@ -30,7 +31,7 @@ "build": "tsc"

"@noble/hashes": "^1.2.0",
"@noble/secp256k1": "^1.7.1",
"buffer": "^6.0.3",
"rxjs": "^7.5.7",
"secp256k1": "^5.0.0",
"ws": "^8.12.1"
}
}

@@ -7,3 +7,3 @@ # lnmessage

- Connect to a lightning node via a WebSocket connection.
- Connect to a lightning node via a WebSocket or TCP Socket connection.
- Works in the Browser and Node without any polyfilling.

@@ -88,2 +88,4 @@ - Initialise with a session secret to have a persistent node public key for the browser.

wsProtocol?: 'ws:' | 'wss:'
/**In Nodejs or React Native you can connect directly via a TCP socket */
tcpSocket?: TCPSocket
/**

@@ -90,0 +92,0 @@ * 32 byte hex encoded private key to be used as the local node secret.

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc