npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tlsjsonproxy

v1.0.0

Published

Creates a HTTP server that acts as a proxy to a JSON-RPC TLS socket-based interface

Downloads

11

Readme

HTTP Proxy Server

This is a small tool developed using Node native modules only (no dependencies) that connects to a TLS-based JSON-RPC server that does not serve a HTTP interface (e.g. ElectrumX) and provides a local HTTP interface you can send your requests to.

For the sake of concurrency, the remote JSON-RPC server must implement the message ID handling (request's and response's "id" property).

This is a command line tool. Not intended to be used as NodeJS library.

How to install

Download this repo and just use the tlsjsonproxy.js file in command line.

For a global install, run npm i -g tlsjsonproxy and use the "tlsjsonproxy" command instead.

How to use

First, try connecting to the remote server to check if it's up. Example:

openssl s_client -connect fortress.qtornado.com:50002

Try pasting a command, e.g.:

{ "method" : "blockchain.block.header", "params": [ 1], "id": "msg_id"}

If everything is all ok, you'll get something like:

{"jsonrpc": "2.0", "result": "010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e61bc6649ffff001d01e36299", "id": "msg_id"}

Now close the connection (Ctrl + C) and let's set up this script to allow us to perform the same request through a HTTP API. The usage is:

node tlsjsonproxy.js <remote server> <remote port> <local port> [<local server=0.0.0.0>]
  • Remote server: the server to connect to
  • Remote port: the port in the remote server
  • Local port: local port in your machine where the HTTP server will listen at
  • Local server (optional): the local network interface (0.0.0.0 for all, 127.0.0.1 to accept loopback connections only or the interface's IP address)

Example:

node tlsjsonproxy.js fortress.qtornado.com 50002 8080

Now you can perform the same request we did before, but using HTTP.

Note: the examples below were generated by Insomnia

Example with cURL command:

curl --request POST \
  --url http://localhost:8081/ \
  --header 'content-type: application/json' \
  --data '{ "method" : "blockchain.block.header", "params": [ 1]}'

Example with Javascript's fetch:

fetch("http://localhost:8081/", {
  "method": "POST",
  "headers": {
    "content-type": "application/json"
  },
  "body": {
    "method": "blockchain.block.header",
    "params": [
      1
    ]
  }
})
.then(response => {
  console.log(response);
})
.catch(err => {
  console.log(err);
});

Example with PHP cURL:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8081",
  CURLOPT_URL => "http://localhost:8081/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{ \"method\" : \"blockchain.block.header\", \"params\": [ 1]}",
  CURLOPT_HTTPHEADER => array(
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}