Compare commits
No commits in common. "671c7ad6a11fcdcd4bbc612568a6341d6042031a" and "714da70209f95efcaa939405f062f6ea2eb930da" have entirely different histories.
671c7ad6a1
...
714da70209
|
@ -5,7 +5,7 @@ import * as fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import log from "./log.js";
|
import log from "./log.js";
|
||||||
|
|
||||||
const config = new Config("lumeweb-relay", "core.confdir");
|
const config = new Config("lumeweb-relay");
|
||||||
|
|
||||||
let configDir;
|
let configDir;
|
||||||
|
|
||||||
|
@ -24,11 +24,11 @@ switch (os.platform()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
config.inject({
|
config.inject({
|
||||||
"core.confDir": configDir,
|
"core.confdir": configDir,
|
||||||
"core.port": 8080,
|
"core.port": 8080,
|
||||||
"core.appPort": 80,
|
"core.apport": 80,
|
||||||
"core.logLevel": "info",
|
"core.loglevel": "info",
|
||||||
"core.pluginDir": path.resolve(configDir, "..", "plugins"),
|
"core.plugindir": path.resolve(configDir, "..", "plugins"),
|
||||||
});
|
});
|
||||||
|
|
||||||
config.load();
|
config.load();
|
||||||
|
|
|
@ -7,11 +7,9 @@ import { start as startSwarm, get as getSwarm } from "./modules/swarm.js";
|
||||||
import * as bip39 from "@scure/bip39";
|
import * as bip39 from "@scure/bip39";
|
||||||
import { wordlist } from "@scure/bip39/wordlists/english";
|
import { wordlist } from "@scure/bip39/wordlists/english";
|
||||||
|
|
||||||
if (!config.str("core.seed")) {
|
if (!config.str("seed")) {
|
||||||
config.save("account", {
|
config.save("account", {
|
||||||
core: {
|
|
||||||
seed: bip39.generateMnemonic(wordlist),
|
seed: bip39.generateMnemonic(wordlist),
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import fastify from "fastify";
|
||||||
import type { FastifyInstance } from "fastify";
|
import type { FastifyInstance } from "fastify";
|
||||||
import { getKeyPair } from "../lib/seed.js";
|
import { getKeyPair } from "../lib/seed.js";
|
||||||
import config from "../config";
|
import config from "../config";
|
||||||
import { getPluginAPI } from "./plugin";
|
|
||||||
|
|
||||||
let app: FastifyInstance;
|
let app: FastifyInstance;
|
||||||
|
|
||||||
|
@ -18,13 +17,5 @@ export async function start() {
|
||||||
res.send(Buffer.from(keyPair.publicKey).toString("hex"));
|
res.send(Buffer.from(keyPair.publicKey).toString("hex"));
|
||||||
});
|
});
|
||||||
|
|
||||||
await getPluginAPI().emitAsync("core.appServer.buildRoutes");
|
|
||||||
|
|
||||||
await app.listen({ port: config.uint("core.appport"), host: "0.0.0.0" });
|
await app.listen({ port: config.uint("core.appport"), host: "0.0.0.0" });
|
||||||
|
|
||||||
getPluginAPI().emit("core.appServer.started");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function get(): FastifyInstance {
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {
|
||||||
ProtocolManager,
|
ProtocolManager,
|
||||||
} from "./swarm.js";
|
} from "./swarm.js";
|
||||||
import { get as getSSl, SSLManager } from "./ssl.js";
|
import { get as getSSl, SSLManager } from "./ssl.js";
|
||||||
import { get as getApp } from "./app.js";
|
|
||||||
import type { HDKey } from "micro-ed25519-hdkey";
|
import type { HDKey } from "micro-ed25519-hdkey";
|
||||||
import corePlugins from "../plugins";
|
import corePlugins from "../plugins";
|
||||||
import Util from "./plugin/util";
|
import Util from "./plugin/util";
|
||||||
|
@ -96,10 +95,6 @@ class PluginAPI extends EventEmitter2 {
|
||||||
return getProtocolManager();
|
return getProtocolManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
get app() {
|
|
||||||
return getApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public loadPlugin(
|
public loadPlugin(
|
||||||
moduleName: string
|
moduleName: string
|
||||||
): (moduleName: string) => Promise<Plugin> {
|
): (moduleName: string) => Promise<Plugin> {
|
||||||
|
@ -147,39 +142,28 @@ export class PluginAPIManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
let plugin: Plugin;
|
let plugin: Plugin;
|
||||||
let pluginPath = paths.shift();
|
|
||||||
try {
|
try {
|
||||||
plugin = require(pluginPath as string) as Plugin;
|
plugin = require(paths.shift() as string) as Plugin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Loaded plugin %s", moduleName);
|
log.debug("Loaded plugin %s", moduleName);
|
||||||
|
|
||||||
const instance = await this.loadPluginInstance(plugin);
|
return this.loadPluginInstance(plugin);
|
||||||
|
|
||||||
if (!instance) {
|
|
||||||
throw new Error(`Corrupt plugin found at ${pluginPath}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance as Plugin;
|
public async loadPluginInstance(plugin: Plugin): Promise<Plugin> {
|
||||||
}
|
|
||||||
|
|
||||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin | boolean> {
|
|
||||||
if ("default" in plugin) {
|
if ("default" in plugin) {
|
||||||
plugin = plugin?.default as Plugin;
|
plugin = plugin?.default as Plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!("name" in plugin)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.name = sanitizeName(plugin.name);
|
plugin.name = sanitizeName(plugin.name);
|
||||||
|
|
||||||
this.registeredPlugins.set(plugin.name, plugin);
|
this.registeredPlugins.set(plugin.name, plugin);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await plugin.plugin(
|
plugin.plugin(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
new Proxy<PluginAPI>(getPluginAPI(), {
|
new Proxy<PluginAPI>(getPluginAPI(), {
|
||||||
get(target: PluginAPI, prop: string): any {
|
get(target: PluginAPI, prop: string): any {
|
||||||
|
|
|
@ -4,30 +4,24 @@ import log from "../log.js";
|
||||||
import config from "../config.js";
|
import config from "../config.js";
|
||||||
|
|
||||||
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
||||||
type SSLCert = string | Buffer | Array<string | Buffer>;
|
|
||||||
|
|
||||||
export class SSLManager {
|
export class SSLManager {
|
||||||
private _key?: Buffer;
|
private _key?: Buffer;
|
||||||
|
private _domain: string;
|
||||||
|
|
||||||
constructor(domain: string) {
|
constructor(domain: string) {
|
||||||
this._domain = domain;
|
this._domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _domain: string;
|
|
||||||
|
|
||||||
get domain(): string {
|
|
||||||
return this._domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _context?: tls.SecureContext;
|
private _context?: tls.SecureContext;
|
||||||
|
|
||||||
get context(): tls.SecureContext {
|
get context(): tls.SecureContext {
|
||||||
return this._context as tls.SecureContext;
|
return this._context as tls.SecureContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _cert?: SSLCert;
|
private _cert?: Buffer;
|
||||||
|
|
||||||
set cert(cert: SSLCert) {
|
set cert(cert: Buffer) {
|
||||||
this._cert = cert;
|
this._cert = cert;
|
||||||
this._maybeUpdateContext();
|
this._maybeUpdateContext();
|
||||||
}
|
}
|
||||||
|
@ -67,21 +61,11 @@ export class SSLManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _maybeUpdateContext() {
|
private _maybeUpdateContext() {
|
||||||
const valid = (value: any) =>
|
if (b4a.isBuffer(this._cert) && b4a.isBuffer(this._key)) {
|
||||||
b4a.isBuffer(value) || typeof value === "string" || Array.isArray(value);
|
this._context = tls.createSecureContext({
|
||||||
|
cert: this._cert,
|
||||||
if (valid(this._cert) && valid(this._key)) {
|
|
||||||
const opts: tls.SecureContextOptions = {
|
|
||||||
key: this._key,
|
key: this._key,
|
||||||
};
|
});
|
||||||
|
|
||||||
if (Array.isArray(this._cert)) {
|
|
||||||
opts.ca = this._cert.slice(1);
|
|
||||||
opts.cert = this._cert[0];
|
|
||||||
} else {
|
|
||||||
opts.cert = this._cert;
|
|
||||||
}
|
|
||||||
this._context = tls.createSecureContext(opts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,13 +618,13 @@ __metadata:
|
||||||
|
|
||||||
"@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git":
|
"@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git":
|
||||||
version: 0.1.7
|
version: 0.1.7
|
||||||
resolution: "@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git#commit=62856686f20c2a627f4bafa92be24ef7f2d49a0d"
|
resolution: "@lumeweb/cfg@https://git.lumeweb.com/LumeWeb/cfg.git#commit=e1d4785240c3815a5b0e376e96e0fb0edfd0c064"
|
||||||
dependencies:
|
dependencies:
|
||||||
arg: "npm:^5.0.2"
|
arg: "npm:^5.0.2"
|
||||||
bsert: "npm:~0.0.10"
|
bsert: "npm:~0.0.10"
|
||||||
deep-to-flat-object: "npm:^1.0.1"
|
deep-to-flat-object: "npm:^1.0.1"
|
||||||
object-path: "npm:^0.11.8"
|
object-path: "npm:^0.11.8"
|
||||||
checksum: 5124fda214790212f99fbb6cea6eaf8b6240bbc3c026e1bd4cab9bd441b8be3ccfc2ea1a77cae1fd50d957d1f902f9c955067805d8233168771286e9dacc0d3d
|
checksum: 1b1120ca829d80713b1ed24d3a7827d82fad78c903ce47a0e289bf5799ce791c0e95a967340e83812e290b2749c5c326f4584a6ec33d8dbacaa8d0c04c5291f5
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue