*Reformat
This commit is contained in:
parent
070b7825e2
commit
20e9511eae
|
@ -1,6 +1,6 @@
|
|||
// @ts-ignore
|
||||
import BConfig from "bcfg";
|
||||
import {errorExit} from "./util.js";
|
||||
import { errorExit } from "./util.js";
|
||||
|
||||
const config = new BConfig("lumeweb-relay");
|
||||
|
||||
|
@ -14,8 +14,7 @@ config.load({
|
|||
});
|
||||
try {
|
||||
config.open("config.conf");
|
||||
} catch (e) {
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
for (const setting of ["relay-domain", "afraid-username", "relay-seed"]) {
|
||||
if (!config.get(setting)) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import {createRequire} from "module";
|
||||
import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const DHT = require("@hyperswarm/dht");
|
||||
import {errorExit} from "./util.js";
|
||||
import { errorExit } from "./util.js";
|
||||
import {
|
||||
deriveMyskyRootKeypair,
|
||||
ed25519Keypair,
|
||||
|
@ -32,7 +32,7 @@ async function start() {
|
|||
|
||||
const keyPair = deriveMyskyRootKeypair(seedPhraseToSeed(seed)[0]);
|
||||
|
||||
node = new DHT({keyPair});
|
||||
node = new DHT({ keyPair });
|
||||
|
||||
await node.ready();
|
||||
|
||||
|
|
16
src/dns.ts
16
src/dns.ts
|
@ -1,15 +1,15 @@
|
|||
import cron from "node-cron";
|
||||
import fetch from "node-fetch";
|
||||
import {get as getDHT} from "./dht.js";
|
||||
import {overwriteRegistryEntry} from "libskynetnode";
|
||||
import {Buffer} from "buffer";
|
||||
import {Parser} from "xml2js";
|
||||
import {URL} from "url";
|
||||
import {errorExit, hashDataKey} from "./util.js";
|
||||
import {pack} from "msgpackr";
|
||||
import { get as getDHT } from "./dht.js";
|
||||
import { overwriteRegistryEntry } from "libskynetnode";
|
||||
import { Buffer } from "buffer";
|
||||
import { Parser } from "xml2js";
|
||||
import { URL } from "url";
|
||||
import { errorExit, hashDataKey } from "./util.js";
|
||||
import { pack } from "msgpackr";
|
||||
import config from "./config.js";
|
||||
|
||||
const {createHash} = await import("crypto");
|
||||
const { createHash } = await import("crypto");
|
||||
|
||||
let activeIp: string;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {start as startDns} from "./dns.js";
|
||||
import {start as startRpc} from "./rpc.js";
|
||||
import {start as startRelay} from "./relay.js";
|
||||
import { start as startDns } from "./dns.js";
|
||||
import { start as startRpc } from "./rpc.js";
|
||||
import { start as startRelay } from "./relay.js";
|
||||
|
||||
await startDns();
|
||||
await startRpc();
|
||||
|
|
22
src/relay.ts
22
src/relay.ts
|
@ -1,27 +1,27 @@
|
|||
// @ts-ignore
|
||||
import DHT from "@hyperswarm/dht";
|
||||
// @ts-ignore
|
||||
import {relay} from "@hyperswarm/dht-relay";
|
||||
import { relay } from "@hyperswarm/dht-relay";
|
||||
// @ts-ignore
|
||||
import Stream from "@hyperswarm/dht-relay/ws";
|
||||
import express, {Express} from "express";
|
||||
import express, { Express } from "express";
|
||||
import path from "path";
|
||||
import {fileURLToPath} from "url";
|
||||
import { fileURLToPath } from "url";
|
||||
import config from "./config.js";
|
||||
import * as http from "http";
|
||||
import * as https from "https";
|
||||
import * as tls from "tls";
|
||||
import * as acme from "acme-client";
|
||||
import {Buffer} from "buffer";
|
||||
import {intervalToDuration} from "date-fns";
|
||||
import { Buffer } from "buffer";
|
||||
import { intervalToDuration } from "date-fns";
|
||||
import cron from "node-cron";
|
||||
import {get as getDHT} from "./dht.js";
|
||||
import { get as getDHT } from "./dht.js";
|
||||
import WS from "ws";
|
||||
// @ts-ignore
|
||||
import DHT from "@hyperswarm/dht";
|
||||
import {pack} from "msgpackr";
|
||||
import {overwriteRegistryEntry} from "libskynetnode";
|
||||
import {hashDataKey} from "./util.js";
|
||||
import { pack } from "msgpackr";
|
||||
import { overwriteRegistryEntry } from "libskynetnode";
|
||||
import { hashDataKey } from "./util.js";
|
||||
|
||||
let sslCtx: tls.SecureContext = tls.createSecureContext();
|
||||
const sslParams: tls.SecureContextOptions = {};
|
||||
|
@ -60,7 +60,7 @@ export async function start() {
|
|||
});
|
||||
const dht = await getDHT();
|
||||
|
||||
let wsServer = new WS.Server({server: httpsServer});
|
||||
let wsServer = new WS.Server({ server: httpsServer });
|
||||
|
||||
wsServer.on("connection", (socket: any) => {
|
||||
relay(dht, new Stream(false, socket));
|
||||
|
@ -82,7 +82,7 @@ async function createOrRenewSSl() {
|
|||
await acme.forge.readCertificateInfo(sslParams.cert as Buffer)
|
||||
).notAfter;
|
||||
|
||||
let duration = intervalToDuration({start: new Date(), end: expires});
|
||||
let duration = intervalToDuration({ start: new Date(), end: expires });
|
||||
|
||||
let daysLeft = (duration.months as number) * 30 + (duration.days as number);
|
||||
|
||||
|
|
26
src/rpc.ts
26
src/rpc.ts
|
@ -1,21 +1,21 @@
|
|||
import crypto from "crypto";
|
||||
import jayson from "jayson/promise/index.js";
|
||||
import {pack, unpack} from "msgpackr";
|
||||
import {Mutex} from "async-mutex";
|
||||
import {createRequire} from "module";
|
||||
import { pack, unpack } from "msgpackr";
|
||||
import { Mutex } from "async-mutex";
|
||||
import { createRequire } from "module";
|
||||
import NodeCache from "node-cache";
|
||||
import {get as getDHT} from "./dht.js";
|
||||
import {rpcMethods} from "./rpc/index.js";
|
||||
import { get as getDHT } from "./dht.js";
|
||||
import { rpcMethods } from "./rpc/index.js";
|
||||
import PocketPKG from "@pokt-network/pocket-js";
|
||||
|
||||
const {Configuration, HttpRpcProvider, PocketAAT, Pocket} = PocketPKG;
|
||||
const { Configuration, HttpRpcProvider, PocketAAT, Pocket } = PocketPKG;
|
||||
import {
|
||||
JSONRPCRequest,
|
||||
JSONRPCResponseWithError,
|
||||
JSONRPCResponseWithResult,
|
||||
} from "jayson";
|
||||
import config, {updateUsePocketGateway, usePocketGateway} from "./config.js";
|
||||
import {errorExit} from "./util.js";
|
||||
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js";
|
||||
import { errorExit } from "./util.js";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
|
@ -102,7 +102,7 @@ async function processRequest(request: RPCRequest): Promise<RPCResponse> {
|
|||
method: request.query,
|
||||
jsonrpc: "2.0",
|
||||
params: request.data,
|
||||
id: 1
|
||||
id: 1,
|
||||
} as unknown as JSONRPCRequest,
|
||||
request.chain
|
||||
);
|
||||
|
@ -130,7 +130,7 @@ async function processRequest(request: RPCRequest): Promise<RPCResponse> {
|
|||
}
|
||||
|
||||
dbData.data = error
|
||||
? {error}
|
||||
? { error }
|
||||
: (rpcResp as unknown as JSONRPCResponseWithResult).result;
|
||||
|
||||
if (!processedRequests.get(reqId) || request.force) {
|
||||
|
@ -198,7 +198,7 @@ export async function processRpcRequest(
|
|||
return new Promise((resolve) => {
|
||||
jsonServer.call(
|
||||
request,
|
||||
{chain},
|
||||
{ chain },
|
||||
(
|
||||
err?: JSONRPCResponseWithError | null,
|
||||
result?: JSONRPCResponseWithResult
|
||||
|
@ -242,7 +242,7 @@ export async function start() {
|
|||
);
|
||||
}
|
||||
|
||||
jsonServer = new jayson.Server(rpcMethods, {useContext: true});
|
||||
jsonServer = new jayson.Server(rpcMethods, { useContext: true });
|
||||
|
||||
(await getDHT("server")).on("connection", (socket: any) => {
|
||||
socket.rawStream._ondestroy = () => false;
|
||||
|
@ -258,7 +258,7 @@ export async function start() {
|
|||
socket.write(pack(await maybeProcessRequest(request)));
|
||||
} catch (error) {
|
||||
console.trace(error);
|
||||
socket.write(pack({error}));
|
||||
socket.write(pack({ error }));
|
||||
}
|
||||
socket.end();
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {maybeMapChainId, reverseMapChainId} from "../util.js";
|
||||
import { maybeMapChainId, reverseMapChainId } from "../util.js";
|
||||
import minimatch from "minimatch";
|
||||
// @ts-ignore
|
||||
import HTTPClient from "algosdk/dist/cjs/src/client/client.js";
|
||||
import {sprintf} from "sprintf-js";
|
||||
import {RpcMethodList} from "./index.js";
|
||||
import { sprintf } from "sprintf-js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
import config from "../config.js";
|
||||
|
||||
const allowedEndpoints: { [endpoint: string]: ("GET" | "POST")[] } = {
|
||||
|
@ -35,7 +35,7 @@ export function proxyRestMethod(
|
|||
let query = args.query ?? false;
|
||||
let fullHeaders = args.fullHeaders ?? {};
|
||||
|
||||
fullHeaders = {...fullHeaders, Referer: "lumeweb_dns_relay"};
|
||||
fullHeaders = { ...fullHeaders, Referer: "lumeweb_dns_relay" };
|
||||
|
||||
if (method) {
|
||||
method = method.toUpperCase();
|
||||
|
@ -76,7 +76,7 @@ export function proxyRestMethod(
|
|||
data = new Uint8Array(Buffer.from(data.data));
|
||||
}
|
||||
|
||||
resp = await client.post(endpoint, data, {...fullHeaders});
|
||||
resp = await client.post(endpoint, data, { ...fullHeaders });
|
||||
break;
|
||||
default:
|
||||
throw new Error("Method Invalid");
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {ethers} from "ethers";
|
||||
import {Pocket, PocketAAT} from "@pokt-network/pocket-js";
|
||||
import {maybeMapChainId, reverseMapChainId} from "../util.js";
|
||||
import {Connection} from "@solana/web3.js";
|
||||
import {getAat, getPocketServer} from "../rpc.js";
|
||||
import config, {usePocketGateway} from "../config.js";
|
||||
import { ethers } from "ethers";
|
||||
import { Pocket, PocketAAT } from "@pokt-network/pocket-js";
|
||||
import { maybeMapChainId, reverseMapChainId } from "../util.js";
|
||||
import { Connection } from "@solana/web3.js";
|
||||
import { getAat, getPocketServer } from "../rpc.js";
|
||||
import config, { usePocketGateway } from "../config.js";
|
||||
|
||||
type RpcProviderMethod = (method: string, params: Array<any>) => Promise<any>;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import {isIp} from "../util.js";
|
||||
import {RpcMethodList} from "./index.js";
|
||||
import {createRequire} from "module";
|
||||
import { isIp } from "../util.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const bns = require("bns");
|
||||
const {StubResolver, RecursiveResolver} = bns;
|
||||
const { StubResolver, RecursiveResolver } = bns;
|
||||
|
||||
const resolverOpt = {
|
||||
tcp: true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {proxyRpcMethod} from "./common.js";
|
||||
import {RpcMethodList} from "./index.js";
|
||||
import { proxyRpcMethod } from "./common.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
|
||||
const rpcMethods: RpcMethodList = {};
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import {RpcMethodList} from "./index.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
// @ts-ignore
|
||||
import rand from "random-key";
|
||||
// @ts-ignore
|
||||
import SPVNode from "hsd/lib/node/spvnode.js";
|
||||
import config from "../config.js";
|
||||
import {createRequire} from "module";
|
||||
import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const {NodeClient} = require("hs-client");
|
||||
const { NodeClient } = require("hs-client");
|
||||
|
||||
let hsdServer: SPVNode;
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ export type RpcMethodList = { [name: string]: Function };
|
|||
|
||||
export * from "./common.js";
|
||||
|
||||
import {default as DnsMethods} from "./dns.js";
|
||||
import {default as EvmMethods} from "./evm.js";
|
||||
import {default as HnsMethods} from "./handshake.js";
|
||||
import {default as SolMethods} from "./solana.js";
|
||||
import {default as AlgoMethods} from "./algorand.js";
|
||||
import { default as DnsMethods } from "./dns.js";
|
||||
import { default as EvmMethods } from "./evm.js";
|
||||
import { default as HnsMethods } from "./handshake.js";
|
||||
import { default as SolMethods } from "./solana.js";
|
||||
import { default as AlgoMethods } from "./algorand.js";
|
||||
|
||||
export const rpcMethods: RpcMethodList = Object.assign(
|
||||
{},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {proxyRpcMethod} from "./common.js";
|
||||
import {RpcMethodList} from "./index.js";
|
||||
import * as chainNetworks from "../networks.json" assert {type: "json"};
|
||||
import { proxyRpcMethod } from "./common.js";
|
||||
import { RpcMethodList } from "./index.js";
|
||||
import * as chainNetworks from "../networks.json" assert { type: "json" };
|
||||
|
||||
export default {
|
||||
getAccountInfo: proxyRpcMethod("getAccountInfo", [
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as chainNetworks from "./networks.json" assert {type: "json"};
|
||||
import {Buffer} from "buffer";
|
||||
import {blake2b} from "libskynet";
|
||||
import * as chainNetworks from "./networks.json" assert { type: "json" };
|
||||
import { Buffer } from "buffer";
|
||||
import { blake2b } from "libskynet";
|
||||
|
||||
type networks = { [net: string]: string };
|
||||
|
||||
|
|
Loading…
Reference in New Issue