From 8151d8a7ec223793701469baf84a93744b74aeba Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 11 Dec 2023 20:23:17 -0500 Subject: [PATCH] feat: initial s5 network bridge --- bridge.mts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 bridge.mts diff --git a/bridge.mts b/bridge.mts new file mode 100644 index 0000000..8dbdbf4 --- /dev/null +++ b/bridge.mts @@ -0,0 +1,30 @@ +import * as fs from "fs"; +import { S5Client } from "@lumeweb/s5-js"; +import { CID } from "@lumeweb/libs5"; +import axios from "axios"; + +type SiteList = { + [domain: string]: { + pubkey: string; + }; +}; + +const sites = JSON.parse( + fs.readFileSync("sites.json", { encoding: "utf8" }), +) as SiteList; + +const client = new S5Client("https://s5.web3portal.com"); + +for (const siteName in sites) { + const site = sites[siteName]; + + const sub = await client.subscribeToEntry(Buffer.from(site.pubkey, "hex")); + sub.listen((entry) => { + const cid = CID.fromRegistry(entry.data); + + axios.post("http://localhost/api/events/siteUpdateReceived", { + cid: cid.toString(), + site: siteName, + }); + }); +}