*Add dist

This commit is contained in:
Derrick Hammer 2023-01-18 03:06:04 -05:00
parent 703d66e3cf
commit 29c4d5f4f8
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 49 additions and 0 deletions

4
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
/// <reference types="node" resolution-mode="require"/>
import type { Peer } from "@lumeweb/peer-discovery";
declare const _default: (pubkey: Buffer, options?: {}) => Promise<boolean | Peer>;
export default _default;

45
dist/index.js vendored Normal file
View File

@ -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