From 29c4d5f4f84f4331722b315f6ac5f9fdeea8968c Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 18 Jan 2023 03:06:04 -0500 Subject: [PATCH] *Add dist --- dist/index.d.ts | 4 ++++ dist/index.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 dist/index.d.ts create mode 100644 dist/index.js diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..bbe5d15 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,4 @@ +/// +import type { Peer } from "@lumeweb/peer-discovery"; +declare const _default: (pubkey: Buffer, options?: {}) => Promise; +export default _default; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..f78a763 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,45 @@ +import { IrcClient } from "@ctrl/irc"; +import jsonStringify from "json-stringify-deterministic"; +import b4a from "b4a"; +import * as ed from "@noble/ed25519"; +import { ripemd160 } from "@noble/hashes/ripemd160"; +import { sha256 } from "@noble/hashes/sha256"; +import { bytesToHex } from "@noble/hashes/utils"; +const hash160 = (data) => ripemd160(sha256(data)); +export default async (pubkey, options = {}) => { + let ircPubKey = await ed.getPublicKey(ed.utils.randomPrivateKey()); + let client = new IrcClient(undefined, bytesToHex(hash160(ircPubKey)).substring(0, 15), { + host: "irc.liberta.casa", + port: 6697, + secure: true, + channels: ["#lumeweb"], + }); + client.connect(); + await new Promise((resolve) => { + client.once("join", resolve); + }); + client.say("#lumeweb", b4a.toBuffer(pubkey).toString("hex")); + return new Promise((resolve, reject) => { + client.on("pm", async (from, text) => { + let json; + try { + json = JSON.parse(text); + } + catch { + return; + } + const verifyData = { + host: json.host, + port: json.port, + timestamp: json.timestamp, + }; + const verifyPayload = jsonStringify(verifyData); + if (!(await ed.verify(b4a.from(json.signature, "hex"), b4a.from(verifyPayload), pubkey))) { + return; + } + client.end(); + resolve({ host: json.host, port: json.port }); + }); + }); +}; +//# sourceMappingURL=index.js.map \ No newline at end of file