import { Client, factory } from "@lumeweb/libkernel/module"; import type { Peer } from "@lumeweb/libpeerdiscovery"; import { hexToBytes } from "@lumeweb/libweb"; const MODULE = "zrjD6CEchDtSex5VHjzMNSAdkJpMNfCtbxSnftgtfvtnsdY"; export class PeerDiscoveryClient extends Client { public async register(source: string): Promise { const bag = this.getBound(source); const ret = await bag.callModule("register"); this.handleError(ret); } public async registerSelf(): Promise { return await this.callModuleReturn("register"); } public async remove(name: string): Promise { return await this.callModuleReturn("remove", { name }); } public async removeAll(): Promise { await this.callModuleReturn("removeAll"); } public async exists(name: string): Promise { return await this.callModuleReturn("remove", { name }); } public async discover(pubkey: string | Uint8Array): Promise { if (typeof pubkey === "string") { pubkey = hexToBytes(pubkey); } return await this.callModuleReturn("discover", { pubkey }); } } export const createClient = factory( PeerDiscoveryClient, MODULE, ); export { Peer };