*Remove use of dynamic imports
This commit is contained in:
parent
5362d83af6
commit
4a4b46df5b
14
src/dht.ts
14
src/dht.ts
|
@ -5,7 +5,11 @@
|
||||||
import DHT from "@hyperswarm/dht";
|
import DHT from "@hyperswarm/dht";
|
||||||
import config from "./config.js";
|
import config from "./config.js";
|
||||||
import { errorExit } from "./error.js";
|
import { errorExit } from "./error.js";
|
||||||
import { dynImport } from "./util.js";
|
import {
|
||||||
|
deriveMyskyRootKeypair,
|
||||||
|
seedPhraseToSeed,
|
||||||
|
validSeedPhrase,
|
||||||
|
} from "libskynet";
|
||||||
|
|
||||||
let node: {
|
let node: {
|
||||||
ready: () => any;
|
ready: () => any;
|
||||||
|
@ -16,14 +20,6 @@ let node: {
|
||||||
let server: any;
|
let server: any;
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const {
|
|
||||||
deriveMyskyRootKeypair,
|
|
||||||
// @ts-ignore
|
|
||||||
Ed25519Keypair,
|
|
||||||
seedPhraseToSeed,
|
|
||||||
validSeedPhrase,
|
|
||||||
} = await dynImport("libskynet");
|
|
||||||
|
|
||||||
const seed = config.str("seed");
|
const seed = config.str("seed");
|
||||||
|
|
||||||
let err = validSeedPhrase(seed);
|
let err = validSeedPhrase(seed);
|
||||||
|
|
14
src/dns.ts
14
src/dns.ts
|
@ -4,14 +4,13 @@ import { Buffer } from "buffer";
|
||||||
import { pack } from "msgpackr";
|
import { pack } from "msgpackr";
|
||||||
import config from "./config.js";
|
import config from "./config.js";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import { dynImport } from "./util.js";
|
import fetch from "node-fetch";
|
||||||
|
import { overwriteRegistryEntry } from "libskynetnode";
|
||||||
import type { DnsProvider } from "@lumeweb/relay-types";
|
import type { DnsProvider } from "@lumeweb/relay-types";
|
||||||
|
// @ts-ignore
|
||||||
|
import { hashDataKey } from "@lumeweb/kernel-utils";
|
||||||
|
|
||||||
let activeIp: string;
|
let activeIp: string;
|
||||||
let fetch: typeof import("node-fetch").default;
|
|
||||||
let overwriteRegistryEntry: typeof import("libskynetnode").overwriteRegistryEntry;
|
|
||||||
let hashDataKey: typeof import("@lumeweb/kernel-utils").hashDataKey;
|
|
||||||
|
|
||||||
const REGISTRY_NODE_KEY = "lumeweb-dht-node";
|
const REGISTRY_NODE_KEY = "lumeweb-dht-node";
|
||||||
|
|
||||||
let dnsProvider: DnsProvider = async (ip) => {};
|
let dnsProvider: DnsProvider = async (ip) => {};
|
||||||
|
@ -37,11 +36,6 @@ async function ipUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function start() {
|
export async function start() {
|
||||||
fetch = (await dynImport("node-fetch")).default;
|
|
||||||
overwriteRegistryEntry = (await dynImport("libskynetnode"))
|
|
||||||
.overwriteRegistryEntry;
|
|
||||||
hashDataKey = (await dynImport("@lumeweb/kernel-utils")).hashDataKey;
|
|
||||||
|
|
||||||
const dht = (await getDHT()) as any;
|
const dht = (await getDHT()) as any;
|
||||||
|
|
||||||
await ipUpdate();
|
await ipUpdate();
|
||||||
|
|
71
src/file.ts
71
src/file.ts
|
@ -1,67 +1,40 @@
|
||||||
import type { Err, progressiveFetchResult } from "libskynet";
|
import type { Err, progressiveFetchResult } from "libskynet";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
|
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
|
||||||
import { dynImport } from "./util.js";
|
|
||||||
import type {
|
import type {
|
||||||
IndependentFileSmall,
|
IndependentFileSmall,
|
||||||
IndependentFileSmallMetadata,
|
IndependentFileSmallMetadata,
|
||||||
} from "@lumeweb/relay-types";
|
} from "@lumeweb/relay-types";
|
||||||
|
import {
|
||||||
|
addContextToErr,
|
||||||
|
blake2b,
|
||||||
|
bufToHex,
|
||||||
|
ed25519Sign,
|
||||||
|
encodePrefixedBytes,
|
||||||
|
encodeU64,
|
||||||
|
defaultPortalList,
|
||||||
|
skylinkToResolverEntryData,
|
||||||
|
encryptFileSmall,
|
||||||
|
decryptFileSmall,
|
||||||
|
entryIDToSkylink,
|
||||||
|
deriveRegistryEntryID,
|
||||||
|
taggedRegistryEntryKeys,
|
||||||
|
namespaceInode,
|
||||||
|
deriveChildSeed,
|
||||||
|
bufToB64,
|
||||||
|
} from "libskynet";
|
||||||
|
|
||||||
|
import { readRegistryEntry, progressiveFetch, upload } from "libskynetnode";
|
||||||
|
|
||||||
const ERR_NOT_EXISTS = "DNE";
|
const ERR_NOT_EXISTS = "DNE";
|
||||||
const STD_FILENAME = "file";
|
const STD_FILENAME = "file";
|
||||||
|
|
||||||
let addContextToErr: typeof import("libskynet").addContextToErr,
|
|
||||||
blake2b: typeof import("libskynet").blake2b,
|
|
||||||
bufToHex: typeof import("libskynet").bufToHex,
|
|
||||||
ed25519Sign: typeof import("libskynet").ed25519Sign,
|
|
||||||
encodePrefixedBytes: typeof import("libskynet").encodePrefixedBytes,
|
|
||||||
encodeU64: typeof import("libskynet").encodeU64,
|
|
||||||
progressiveFetch: typeof import("libskynet").progressiveFetch,
|
|
||||||
defaultPortalList: typeof import("libskynet").defaultPortalList,
|
|
||||||
readRegistryEntry: typeof import("libskynetnode/dist/registryread.js").readRegistryEntry,
|
|
||||||
upload: typeof import("libskynetnode").upload,
|
|
||||||
skylinkToResolverEntryData: typeof import("libskynet").skylinkToResolverEntryData,
|
|
||||||
encryptFileSmall: typeof import("libskynet").encryptFileSmall,
|
|
||||||
deriveChildSeed: typeof import("libskynet").deriveChildSeed,
|
|
||||||
bufToB64: typeof import("libskynet").bufToB64,
|
|
||||||
decryptFileSmall: typeof import("libskynet").decryptFileSmall,
|
|
||||||
entryIDToSkylink: typeof import("libskynet").entryIDToSkylink,
|
|
||||||
deriveRegistryEntryID: typeof import("libskynet").deriveRegistryEntryID,
|
|
||||||
taggedRegistryEntryKeys: typeof import("libskynet").taggedRegistryEntryKeys,
|
|
||||||
namespaceInode: typeof import("libskynet").namespaceInode;
|
|
||||||
|
|
||||||
async function loadLibs() {
|
|
||||||
const libskynet = await dynImport("libskynet");
|
|
||||||
addContextToErr = libskynet.addContextToErr;
|
|
||||||
bufToHex = libskynet.bufToHex;
|
|
||||||
ed25519Sign = libskynet.ed25519Sign;
|
|
||||||
encodePrefixedBytes = libskynet.encodePrefixedBytes;
|
|
||||||
encodeU64 = libskynet.encodeU64;
|
|
||||||
defaultPortalList = libskynet.defaultPortalList;
|
|
||||||
skylinkToResolverEntryData = libskynet.skylinkToResolverEntryData;
|
|
||||||
encryptFileSmall = libskynet.encryptFileSmall;
|
|
||||||
deriveChildSeed = libskynet.deriveChildSeed;
|
|
||||||
bufToB64 = libskynet.bufToB64;
|
|
||||||
decryptFileSmall = libskynet.decryptFileSmall;
|
|
||||||
entryIDToSkylink = libskynet.entryIDToSkylink;
|
|
||||||
deriveRegistryEntryID = libskynet.deriveRegistryEntryID;
|
|
||||||
taggedRegistryEntryKeys = libskynet.taggedRegistryEntryKeys;
|
|
||||||
namespaceInode = libskynet.namespaceInode;
|
|
||||||
|
|
||||||
progressiveFetch = (await dynImport("libskynetnode/dist/progressivefetch.js"))
|
|
||||||
.progressiveFetch;
|
|
||||||
readRegistryEntry = (await dynImport("libskynetnode/dist/registryread.js"))
|
|
||||||
.readRegistryEntry;
|
|
||||||
upload = (await dynImport("libskynetnode")).upload;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function overwriteRegistryEntry(
|
async function overwriteRegistryEntry(
|
||||||
keypair: any,
|
keypair: any,
|
||||||
datakey: Uint8Array,
|
datakey: Uint8Array,
|
||||||
data: Uint8Array,
|
data: Uint8Array,
|
||||||
revision: bigint
|
revision: bigint
|
||||||
): Promise<null> {
|
): Promise<null> {
|
||||||
await loadLibs();
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (data.length > 86) {
|
if (data.length > 86) {
|
||||||
reject("provided data is too large to fit in a registry entry");
|
reject("provided data is too large to fit in a registry entry");
|
||||||
|
@ -122,7 +95,6 @@ async function overwriteRegistryEntry(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function verifyRegistryWrite(response: Response): Promise<Err> {
|
async function verifyRegistryWrite(response: Response): Promise<Err> {
|
||||||
await loadLibs();
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (!("status" in response)) {
|
if (!("status" in response)) {
|
||||||
resolve("response did not contain a status");
|
resolve("response did not contain a status");
|
||||||
|
@ -141,7 +113,6 @@ async function createIndependentFileSmall(
|
||||||
userInode: string,
|
userInode: string,
|
||||||
fileData: Uint8Array
|
fileData: Uint8Array
|
||||||
): Promise<[IndependentFileSmall, Err]> {
|
): Promise<[IndependentFileSmall, Err]> {
|
||||||
await loadLibs();
|
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
||||||
if (errNI !== null) {
|
if (errNI !== null) {
|
||||||
|
@ -275,7 +246,6 @@ async function openIndependentFileSmall(
|
||||||
seed: Uint8Array,
|
seed: Uint8Array,
|
||||||
userInode: string
|
userInode: string
|
||||||
): Promise<[IndependentFileSmall, Err]> {
|
): Promise<[IndependentFileSmall, Err]> {
|
||||||
await loadLibs();
|
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
let [inode, errNI] = namespaceInode("IndependentFileSmall", userInode);
|
||||||
if (errNI !== null) {
|
if (errNI !== null) {
|
||||||
|
@ -378,7 +348,6 @@ async function overwriteIndependentFileSmall(
|
||||||
file: IndependentFileSmall,
|
file: IndependentFileSmall,
|
||||||
newData: Uint8Array
|
newData: Uint8Array
|
||||||
): Promise<Err> {
|
): Promise<Err> {
|
||||||
await loadLibs();
|
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
// Create a new metadata for the file based on the current file
|
// Create a new metadata for the file based on the current file
|
||||||
// metadata. Need to update the largest historic size.
|
// metadata. Need to update the largest historic size.
|
||||||
|
|
|
@ -13,8 +13,8 @@ import {
|
||||||
setSslContext,
|
setSslContext,
|
||||||
} from "./ssl.js";
|
} from "./ssl.js";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import { getSeed, loadUtilFunctions } from "./util.js";
|
import { getSeed } from "./util.js";
|
||||||
import { getRouter, resetRouter, setRouter } from "./relay";
|
import { getRouter, resetRouter, setRouter } from "./relay.js";
|
||||||
import {
|
import {
|
||||||
createIndependentFileSmall,
|
createIndependentFileSmall,
|
||||||
openIndependentFileSmall,
|
openIndependentFileSmall,
|
||||||
|
@ -118,7 +118,6 @@ export function getPluginAPI(): PluginApiManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadPlugins() {
|
export async function loadPlugins() {
|
||||||
await loadUtilFunctions();
|
|
||||||
for (const plugin of config.array("plugins")) {
|
for (const plugin of config.array("plugins")) {
|
||||||
await getPluginAPI().loadPlugin(plugin);
|
await getPluginAPI().loadPlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import config from "./config";
|
import config from "./config";
|
||||||
|
import { seedPhraseToSeed } from "libskynet";
|
||||||
let seedPhraseToSeed: typeof import("libskynet").seedPhraseToSeed;
|
|
||||||
|
|
||||||
export async function loadUtilFunctions() {
|
|
||||||
seedPhraseToSeed = (await dynImport("libskynet")).seedPhraseToSeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function dynImport(module: string) {
|
export function dynImport(module: string) {
|
||||||
return Function(`return import("${module}")`)() as Promise<any>;
|
return Function(`return import("${module}")`)() as Promise<any>;
|
||||||
|
|
Loading…
Reference in New Issue