2022-07-24 03:16:34 +00:00
|
|
|
//const require = createRequire(import.meta.url);
|
|
|
|
//import { createRequire } from "module";
|
2022-07-19 22:24:53 +00:00
|
|
|
|
2022-11-26 07:59:07 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import Hyperswarm from "hyperswarm";
|
2022-08-03 06:02:40 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import DHT from "@hyperswarm/dht";
|
2022-06-27 17:53:00 +00:00
|
|
|
|
2022-11-26 07:59:07 +00:00
|
|
|
// @ts-ignore
|
|
|
|
import sodium from "sodium-universal";
|
|
|
|
import b4a from "b4a";
|
2022-12-19 16:42:51 +00:00
|
|
|
import { log } from "../log.js";
|
2022-12-18 18:32:59 +00:00
|
|
|
import { getKeyPair } from "../lib/seed.js";
|
2022-11-26 07:59:07 +00:00
|
|
|
|
|
|
|
const LUMEWEB = b4a.from("lumeweb");
|
2022-12-04 17:03:09 +00:00
|
|
|
export const LUMEWEB_TOPIC_HASH = b4a.allocUnsafe(32);
|
|
|
|
sodium.crypto_generichash(LUMEWEB_TOPIC_HASH, LUMEWEB);
|
2022-11-26 07:59:07 +00:00
|
|
|
|
|
|
|
export type SecretStream = any;
|
|
|
|
|
|
|
|
let node: Hyperswarm;
|
2022-06-27 17:53:00 +00:00
|
|
|
|
2022-11-26 22:13:02 +00:00
|
|
|
export async function start() {
|
2022-09-22 14:17:37 +00:00
|
|
|
const keyPair = getKeyPair();
|
2022-06-27 17:53:00 +00:00
|
|
|
|
2022-11-26 07:59:07 +00:00
|
|
|
node = new Hyperswarm({ keyPair, dht: new DHT({ keyPair }) });
|
2022-06-27 17:53:00 +00:00
|
|
|
|
2022-11-26 07:59:07 +00:00
|
|
|
// @ts-ignore
|
|
|
|
await node.dht.ready();
|
|
|
|
await node.listen();
|
2022-12-04 17:03:09 +00:00
|
|
|
node.join(LUMEWEB_TOPIC_HASH);
|
2022-07-19 22:24:53 +00:00
|
|
|
|
2022-12-06 22:03:30 +00:00
|
|
|
log.info(
|
|
|
|
"Relay Identity is",
|
|
|
|
b4a.from(node.dht.defaultKeyPair.publicKey).toString("hex")
|
|
|
|
);
|
|
|
|
|
2022-07-19 22:31:15 +00:00
|
|
|
return node;
|
2022-06-27 17:53:00 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 22:13:02 +00:00
|
|
|
export function get(): Hyperswarm {
|
2022-07-19 22:31:15 +00:00
|
|
|
return node;
|
2022-06-27 17:53:00 +00:00
|
|
|
}
|