*Restructure to transpile to commonjs since vercel pkg does not support ESM
This commit is contained in:
parent
75afac3de1
commit
0713216cd3
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/relay",
|
"name": "@lumeweb/relay",
|
||||||
"type": "module",
|
"type": "commonjs",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
|
@ -50,6 +50,7 @@
|
||||||
"@types/sprintf-js": "^1.1.2",
|
"@types/sprintf-js": "^1.1.2",
|
||||||
"esbuild": "^0.14.49",
|
"esbuild": "^0.14.49",
|
||||||
"hyper-typings": "^1.0.0",
|
"hyper-typings": "^1.0.0",
|
||||||
"prettier": "^2.7.1"
|
"prettier": "^2.7.1",
|
||||||
|
"rollup": "^2.77.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
|
//const require = createRequire(import.meta.url);
|
||||||
|
//import { createRequire } from "module";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import BConfig from "bcfg";
|
import BConfig from "bcfg";
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import { createRequire } from "module";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { errorExit } from "./error.js";
|
import { errorExit } from "./error.js";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
const config = new BConfig("lumeweb-relay");
|
const config = new BConfig("lumeweb-relay");
|
||||||
|
|
||||||
let configLocation;
|
let configLocation;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createRequire } from "module";
|
//const require = createRequire(import.meta.url);
|
||||||
|
//import { createRequire } from "module";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
const DHT = require("@hyperswarm/dht");
|
const DHT = require("@hyperswarm/dht");
|
||||||
import {
|
import {
|
||||||
deriveMyskyRootKeypair,
|
deriveMyskyRootKeypair,
|
||||||
|
|
|
@ -10,8 +10,7 @@ import config from "./config.js";
|
||||||
import { hashDataKey } from "@lumeweb/kernel-utils";
|
import { hashDataKey } from "@lumeweb/kernel-utils";
|
||||||
import { errorExit } from "./error.js";
|
import { errorExit } from "./error.js";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
import { createHash } from "crypto";
|
||||||
const { createHash } = await import("crypto");
|
|
||||||
|
|
||||||
let activeIp: string;
|
let activeIp: string;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,10 @@ import config from "./config";
|
||||||
|
|
||||||
log.setDefaultLevel(config.str("log-level"));
|
log.setDefaultLevel(config.str("log-level"));
|
||||||
|
|
||||||
await startRpc();
|
async function boot() {
|
||||||
await startRelay();
|
await startRpc();
|
||||||
|
await startRelay();
|
||||||
|
}
|
||||||
|
|
||||||
process.on("uncaughtException", function (err) {
|
process.on("uncaughtException", function (err) {
|
||||||
console.log("Caught exception: " + err);
|
console.log("Caught exception: " + err);
|
||||||
|
|
34
src/relay.ts
34
src/relay.ts
|
@ -30,19 +30,14 @@ import { sprintf } from "sprintf-js";
|
||||||
let sslCtx: tls.SecureContext = tls.createSecureContext();
|
let sslCtx: tls.SecureContext = tls.createSecureContext();
|
||||||
const sslParams: tls.SecureContextOptions = { cert: "", key: "" };
|
const sslParams: tls.SecureContextOptions = { cert: "", key: "" };
|
||||||
|
|
||||||
const sslPrivateKey = await acme.forge.createPrivateKey();
|
let acmeClient: acme.Client;
|
||||||
const acmeClient = new acme.Client({
|
|
||||||
accountKey: sslPrivateKey,
|
|
||||||
directoryUrl: isSSlStaging()
|
|
||||||
? acme.directory.letsencrypt.staging
|
|
||||||
: acme.directory.letsencrypt.production,
|
|
||||||
});
|
|
||||||
|
|
||||||
let app: Express;
|
let app: Express;
|
||||||
let router = express.Router();
|
let router = express.Router();
|
||||||
|
|
||||||
const FILE_CERT_NAME = "/lumeweb/relay/ssl.crt";
|
const FILE_CERT_NAME = "/lumeweb/relay/ssl.crt";
|
||||||
const FILE_KEY_NAME = "/lumeweb/relay/ssl.key";
|
const FILE_KEY_NAME = "/lumeweb/relay/ssl.key";
|
||||||
|
const FILE_ACCOUNT_KEY_NAME = "/lumeweb/relay/account.key";
|
||||||
|
|
||||||
type SslData = { crt: IndependentFileSmall; key: IndependentFileSmall };
|
type SslData = { crt: IndependentFileSmall; key: IndependentFileSmall };
|
||||||
|
|
||||||
|
@ -155,6 +150,30 @@ async function createOrRenewSSl(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let accountKey: boolean | IndependentFileSmall | Buffer = await getSslFile(
|
||||||
|
FILE_ACCOUNT_KEY_NAME
|
||||||
|
);
|
||||||
|
|
||||||
|
if (accountKey) {
|
||||||
|
accountKey = Buffer.from((accountKey as IndependentFileSmall).fileData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accountKey) {
|
||||||
|
accountKey = await acme.forge.createPrivateKey();
|
||||||
|
await createIndependentFileSmall(
|
||||||
|
getSeed(),
|
||||||
|
FILE_ACCOUNT_KEY_NAME,
|
||||||
|
accountKey
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
acmeClient = new acme.Client({
|
||||||
|
accountKey: accountKey as Buffer,
|
||||||
|
directoryUrl: isSSlStaging()
|
||||||
|
? acme.directory.letsencrypt.staging
|
||||||
|
: acme.directory.letsencrypt.production,
|
||||||
|
});
|
||||||
|
|
||||||
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
const [certificateKey, certificateRequest] = await acme.forge.createCsr({
|
||||||
commonName: config.str("domain"),
|
commonName: config.str("domain"),
|
||||||
});
|
});
|
||||||
|
@ -228,6 +247,7 @@ async function getCertInfo() {
|
||||||
async function getSslCert(): Promise<IndependentFileSmall | boolean> {
|
async function getSslCert(): Promise<IndependentFileSmall | boolean> {
|
||||||
return getSslFile(FILE_CERT_NAME);
|
return getSslFile(FILE_CERT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSslKey(): Promise<IndependentFileSmall | boolean> {
|
async function getSslKey(): Promise<IndependentFileSmall | boolean> {
|
||||||
return getSslFile(FILE_KEY_NAME);
|
return getSslFile(FILE_KEY_NAME);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
//const require = createRequire(import.meta.url);
|
||||||
|
//import { createRequire } from "module";
|
||||||
|
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import jayson from "jayson/promise/index.js";
|
import jayson from "jayson/promise/index.js";
|
||||||
import { pack, unpack } from "msgpackr";
|
import { pack, unpack } from "msgpackr";
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import { createRequire } from "module";
|
|
||||||
import NodeCache from "node-cache";
|
import NodeCache from "node-cache";
|
||||||
import { get as getDHT } from "./dht.js";
|
import { get as getDHT } from "./dht.js";
|
||||||
import { rpcMethods } from "./rpc/index.js";
|
import { rpcMethods } from "./rpc/index.js";
|
||||||
|
@ -19,8 +21,6 @@ import {
|
||||||
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js";
|
import config, { updateUsePocketGateway, usePocketGateway } from "./config.js";
|
||||||
import { ERR_NOT_READY, errorExit } from "./error.js";
|
import { ERR_NOT_READY, errorExit } from "./error.js";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
|
|
||||||
const stringify = require("json-stable-stringify");
|
const stringify = require("json-stable-stringify");
|
||||||
const pendingRequests = new NodeCache();
|
const pendingRequests = new NodeCache();
|
||||||
const processedRequests = new NodeCache({
|
const processedRequests = new NodeCache({
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
//import { createRequire } from "module";
|
||||||
|
//const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
import { isIp } from "../util.js";
|
import { isIp } from "../util.js";
|
||||||
import { RpcMethodList } from "./index.js";
|
import { RpcMethodList } from "./index.js";
|
||||||
import { createRequire } from "module";
|
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
const bns = require("bns");
|
const bns = require("bns");
|
||||||
const { StubResolver, RecursiveResolver } = bns;
|
const { StubResolver, RecursiveResolver } = bns;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
|
//const require = createRequire(import.meta.url);
|
||||||
|
//import { createRequire } from "module";
|
||||||
|
|
||||||
import { RpcMethodList } from "./index.js";
|
import { RpcMethodList } from "./index.js";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import rand from "random-key";
|
import rand from "random-key";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import SPVNode from "hsd/lib/node/spvnode.js";
|
import SPVNode from "hsd/lib/node/spvnode.js";
|
||||||
import config from "../config.js";
|
import config from "../config.js";
|
||||||
import { createRequire } from "module";
|
|
||||||
import { ERR_NOT_READY } from "../error.js";
|
import { ERR_NOT_READY } from "../error.js";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
const { NodeClient } = require("hs-client");
|
const { NodeClient } = require("hs-client");
|
||||||
|
|
||||||
let hsdServer: SPVNode;
|
let hsdServer: SPVNode;
|
||||||
|
@ -54,6 +55,7 @@ if (!config.bool("hsd-use-external-node")) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(async () => {
|
||||||
try {
|
try {
|
||||||
await hsdServer.ensure();
|
await hsdServer.ensure();
|
||||||
await hsdServer.open();
|
await hsdServer.open();
|
||||||
|
@ -63,6 +65,7 @@ if (!config.bool("hsd-use-external-node")) {
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error((e as Error).stack);
|
console.error((e as Error).stack);
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
} else {
|
} else {
|
||||||
clientArgs = {
|
clientArgs = {
|
||||||
network: config.str("hsd-network-type"),
|
network: config.str("hsd-network-type"),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { proxyRpcMethod } from "./common.js";
|
import { proxyRpcMethod } from "./common.js";
|
||||||
import { RpcMethodList } from "./index.js";
|
import { RpcMethodList } from "./index.js";
|
||||||
import * as chainNetworks from "../networks.json" assert { type: "json" };
|
import * as chainNetworks from "../networks.json";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getAccountInfo: proxyRpcMethod("getAccountInfo", [
|
getAccountInfo: proxyRpcMethod("getAccountInfo", [
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import * as chainNetworks from "./networks.json" assert { type: "json" };
|
import * as chainNetworks from "./networks.json";
|
||||||
|
|
||||||
type networks = { [net: string]: string };
|
type networks = { [net: string]: string };
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"target": "es2020",
|
||||||
"module": "esnext",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"outDir": "build",
|
"outDir": "build",
|
||||||
|
|
Loading…
Reference in New Issue